我正在尝试安排一个函数调用,函数是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);
}
答案 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);
}