2

これは私のコードです。スプラッシュ スクリーンの作成方法と、メニュー スクリーンでの表示方法がわかりません。すべての .h は BaseScreen に接続する必要があり、BaseScreen は cocos2d レイヤーで接続されたものになります。私のコードで私を助けてください。私のエミュレーターに表示される唯一のことは、HelloWorldScreen.h でコーディングしたスプライトです。

SplashScreen.h

ifndef __SPLASH_SCREEN_H__
define __SPLASH_SCREEN_H__

include "BaseScreen.h"
include "cocos2d.h"

class SplashScreen : BaseScreen 
{
public:
void update ();
static cocos2d::CCSprite* splashScreen;
int time;
MenuScreen menuScreen;
};
endif

HelloWorldScene.cpp

include "HelloWorldScene.h"
include "SplashScreen.h"
include "cocos2d.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();

// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();

// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{

// 1. super init first
if ( !CCLayer::init() )
{
    return false;
}

CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();


// 2. add a menu item with "X" image, which is clicked to quit the program
//    you may modify it.

// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                    "CloseNormal.png",
                                    "CloseSelected.png",
                                    this,
                                    menu_selector(HelloWorld::menuCloseCallback));

pCloseItem->setPosition(ccp(origin.x + visibleSize.width -                       pCloseItem->getContentSize().width/2 ,
                            origin.y + pCloseItem->getContentSize().height/2));

// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);


// 3. add your codes below...

// create background image from png
    CCSprite *splashScreen = CCSprite::create("company.png");
    // position the background image at the center of window
    splashScreen->setPosition(ccp(size.width / 2, size.height / 2));


    // add background image at z-position = -1, bottom of all
    this->addChild(splashScreen, -1);

    // calculate the scaling factor to fill the window size
    float bX = size.width / splashScreen->getContentSize().width;
    float bY = size.height / splashScreen->getContentSize().height;

    // set the scaling factor to the background image
    splashScreen->setScaleX(bX);
    splashScreen->setScaleY(bY);

return true;
}


//callfuncN_selector(MainScene::spriteMoveFinished)
//backcalls the function spriteMoveFinished()
void HelloWorld::spriteMoveFinished(CCNode* pSender)
{
CCSprite *sprite = (CCSprite *)pSender;
this->removeChild(sprite, true);
}


void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();

if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
endif
}

BaseScreen.h

ifndef __BASE_SCREEN_H__
define __BASE_SCREEN_H__

include "cocos2d.h"

class BaseScreen : public cocos2d::CCLayer
{
public:
//  BaseScreen getParent ();
void loadNewScreen (BaseScreen newScreen);
void update ();
//  BaseScreen *parentBaseScene;
};
endif
4

4 に答える 4

0

このリンクを試してみてください http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/

#include "HelloWorldScene.h" 
#include "OptionsScene.h" 
#include "SplashScene.h" 
#include "SimpleAudioEngine.h" 
#include "RedirectMethods.h" 

using namespace cocos2d;
using namespace CocosDenshion;

CCScene* SplashScene::scene() {
    CCScene *scene = CCScene::create();
    SplashScene *layer = SplashScene::create();
    scene->addChild(layer);
    return scene;
}

bool SplashScene::init() {
    if (!CCLayer::init()) {
        return false;
    }

    CCSize screenSize = CCDirector::sharedDirector()->getWinSize();

    CCSprite* logomarca = CCSprite::create("cocos2dx_logo.png");
    logomarca->setPosition(ccp(screenSize.width / 2, screenSize.height / 2));
    this->addChild(logomarca, 1);

    CCFiniteTimeAction *seq1 = CCSequence::create(CCDelayTime::create(3.0),
            CCCallFuncN::create(this,
                    callfuncN_selector(RedirectMethods::MenuScene)), NULL);

    this->runAction(seq1);

    return true;
}

またはこれを試してみてください。解決することを願っています

于 2013-09-27T06:48:56.297 に答える
0

アプリケーションを起動してスプライトを表示する CCLayer からクラスを継承させることができます。次に、onEnterTransitionDidFinish メソッドをオーバーライドできます。

 void SplashScreen::onEnterTransitionDidFinish(){
  CCScene * sceneAfterSplashScreen = StartLayer::scene();
  CCDirector::sharedDirector()->replaceScene(sceneAfterSplashScreen);
}

スプラッシュ スクリーンが画面に到着すると、新しいシーンのロードと置換が開始されます。

于 2013-09-27T07:25:30.077 に答える