Cocos2d-x安排一个电话

时间:2014-05-20 14:27:45

标签: cocos2d-x cocos2d-x-3.0

我正在尝试安排一个函数调用,函数是changeScene(),它永远不会被调用

知道我做错了什么吗?

Cocos-2d-x 3.0

#include "LoadingScene.h"
LoadingScene::LoadingScene(){}

LoadingScene::~LoadingScene(){}

bool LoadingScene::init() {
    return Scene::init();
}

void LoadingScene::onEnter(){
    // add background to current scene
    Sprite *background = Sprite::create("splash.png");
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    background->setPosition(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2);
    this->addChild(background);

    // start ansyc method load the atlas.png
    Director::getInstance()->getTextureCache()->addImageAsync("atlas.png", CC_CALLBACK_1(LoadingScene::loadingCallBack, this));
}

void LoadingScene::loadingCallBack(Texture2D *texture){
    AtlasLoader::getInstance()->loadAtlas("atlas.txt", texture);
    this->scheduleOnce(schedule_selector(LoadingScene::changeScene), 2.0f);
}

void LoadingScene::changeScene(float dt) {
    auto scene = WelcomeScene::create();
    TransitionScene *transition = TransitionFade::create(1, scene);
    Director::getInstance()->replaceScene(transition);
}

2 个答案:

答案 0 :(得分:1)

<{>>在LoadingScene::onEnter()中,您必须获得文件的绝对路径:

string fullPath = FileUtils::getInstance()->fullPathForFilename("atlas.png");
Director::getInstance()->getTextureCache()->addImageAsync(fullPath, CC_CALLBACK_1(LoadingScene::loadingCallBack, this));

该方法搜索可以扩展的多个路径。请参阅FileUtils::fullPathForFilename()

的说明

答案 1 :(得分:0)

您需要添加CCLayer :: onEnter();

    void LoadingScene::loadingCallBack(Texture2D *texture){
     CCLayer::onEnter();//add this line
    AtlasLoader::getInstance()->loadAtlas("atlas.txt", texture);
    this->scheduleOnce(schedule_selector(LoadingScene::changeScene), 2.0f);
}