2013-09-27 6 views
2

이것은 내 코드입니다. 스플래시 화면을 만드는 방법과 내 메뉴 화면에서 어떻게 표시할지 모릅니다. 모든 .h는 BaseScreen에 연결되어야하며 BaseScreen은 cocos2d 계층에 연결된 BaseScreen이됩니다. 제 코드를 도와주세요. 내 에뮬레이터에 나타납니다 만 일을 할 것은 스프라이트 HelloWorldScreen.h에있는 I 코드안드로이드 cocos2dx 스플래시 화면을 만드는 방법은?

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 
+0

를 작성하면 iOS 또는 Android 용으로 개발하고 있습니까? –

+0

나는 cocos2dx에 대한 안드로이드 게임을 개발 중입니다. – Dana

답변

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; 
} 

을 찾을 수 있습니다이 링크를 시도하거나 내가 그것을 해결 희망이 하나를 시도 그것을

+0

uhm cocos2dx의 스플래시 화면 링크가 있습니까? 링크를 주셔서 감사합니다 – Dana

+0

이미 무료로 소스 코드를 다운로드 할 수있는 스플래시 화면이있는 게임이 있습니까? – Dana

0
당신은 클래스 상속을 할 수

응용 프로그램을 시작하고 스프라이트를 표시하는 CCLayer에서. 시작 화면이 화면에 도착했을 때 그것은 새로운 장면을로드하고 교체하기 시작입니다,

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

: 그럼 당신은 onEnterTransitionDidFinish 방법을 대체 할 수 있습니다.

+0

좋아, 내 수업 HelloWorldScene이 그 수업이 될 수 있니? 거기에 내가이 코드를 넣을 것입니다. 맞습니까? 답변 주셔서 감사합니다. 다음에이 코드를 시도해 보겠습니다. – Dana

+0

HelloWorldScene 클래스에 코드를 넣은 다음 void -----> onEnterTransitionDidFinish(); HelloWorldScene에서.그러면 오류가 발생합니다 : cocos2d :: CCLayeronEnterTransitionDidFinish를 무시하고 오류 : 'HelloWorld :: onEnterTransitionDidFinish()'멤버 함수가 'HelloWorld'클래스에 선언되지 않았습니다. 나는 내 초보자이기 때문에 이해하기가 어렵다. – Dana

+0

답장을 보내 주셔서 감사합니다.이 한 줄의 코드로 시작 화면을 완성했습니다. CCDirector :: sharedDirector() -> replaceScene (CCTransitionFade :: create (3.0f , MenuScene :: scene())); – Dana

3

저는 scheduleOnce 기능을 사용하고 있습니다.

void Splash::onEnter(){ 
    CCLayer::onEnter(); 
    CCLog("onEnter"); 
    this->scheduleOnce(schedule_selector(Splash::finishSplash),2.0f); 
} 

void Splash::finishSplash(float dt){ 
    CCDirector::sharedDirector()->replaceScene(GameWall::scene()); 
} 

2 초 후, 스플래시 화면을 끝내고 GameWall Screen을 시작하십시오. 그게 다예요.

4

다음은 Android에서 스플래시 화면 장면을 추가하는 3 단계입니다. cocos2d-x 사용하기 3.4. 희망이 도움이!

1 SplashScene.cpp

만들기
#include "SplashScene.h" 
    #include "HomeScene.h" 

    using namespace cocos2d; 

    cocos2d::Scene* SplashScene::createScene() 
    { 
     // 'scene' is an autorelease object 
     auto scene = Scene::create(); 

     // 'layer' is an autorelease object 
     auto layer = SplashScene::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 SplashScene::init() 
{ 
    if (!Layer::init()) 
    { 
     return false; 
    } 

    auto visibleSize = Director::getInstance()->getVisibleSize(); 

    auto sprite = Sprite::create("splash.png"); 

    // position the sprite on the center of the screen 
    sprite->setPosition(Vec2(visibleSize.width/2 , visibleSize.height/2)); 

    // add the sprite as a child to this layer 
    this->addChild(sprite, 0); 

    return true; 
} 

void SplashScene::onEnter() { 
    Layer::onEnter(); 

    // Wait for 0.5 seconds to load main scene 
    this->scheduleOnce(schedule_selector(SplashScene::finishSplash), 0.5f); 
} 

void SplashScene::finishSplash(float dt) { 
    // ... do whatever other initializations here 
    // Show the actual main scene 
    Director::getInstance()->replaceScene(HomeScene::createScene()); 
} 

2 SplashScene.h

#ifndef __SplashScene__ 
#define __SplashScene__ 

#include <stdio.h> 
#include "cocos2d.h" 

USING_NS_CC; 

class SplashScene : public cocos2d::Layer 
{ 
public: 
    // there's no 'id' in cpp, so we recommend returning the class instance pointer 
    static Scene* createScene(); 

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone 
    virtual bool init(); 

    void onEnter(); 

    void finishSplash(float dt); 

    // implement the "static create()" method manually 
    CREATE_FUNC(SplashScene); 
}; 

#endif /* defined(__stickerPuzzle__SplashScene__) */ 

3 수정 AppDelegate.cpp

bool AppDelegate::applicationDidFinishLaunching() { 
    // initialize director 
    auto director = Director::getInstance(); 
    auto glview = director->getOpenGLView(); 
    if(!glview) { 
     glview = GLViewImpl::create("My Game"); 
     director->setOpenGLView(glview); 
    } 

    // set FPS. the default value is 1.0/60 if you don't call this 
    director->setAnimationInterval(1.0/60); 

    // ... other stuff ... 

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 
    // On Android - start the splash scene first 
    auto scene = SplashScene::createScene(); 
    director->runWithScene(scene); 
#endif 

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) 
    // On iOS, no need to add splash scene, start main scene directly 
    auto scene = HomeScene::createScene(); 
    director->runWithScene(scene); 
#endif 

    return true; 
} 
관련 문제