c++ - 尝试使用 Cocos2D-x C++ 调用初始化函数
问题描述
但是我的 init 函数从未被调用,我检查了断点。
这是我在 SplashScene.cpp 上的代码的一部分:
Scene* SplashScene::createScene()
{
auto scene = Scene::create();
auto layer = Scene::create();
scene->addChild(layer);
return scene;
}
// on "init" you need to initialize your instance
bool SplashScene::init()
{
//////////////////////////////
// 1. super init first
if (!Layer::init())
{
return false;
}
SonarCocosHelper::UI::AddCentredBackground(MAIN_MENU_BACKGROUND_FILEPATH, this);
scheduleOnce(schedule_selector(SplashScene::SwitchToMainMenu), 5);
return true;
}
这是我在 AppDelegate.cpp 上的代码的一部分(就像在教程中一样):
// create a scene. it's an autorelease object
auto scene = SplashScene::createScene();
// run
director->runWithScene(scene);
return true;
解决方案
#Botje 给我答案:
在我的 Scene* SplashScene::createScene() 实现中,我替换了
auto layer = Scene::create();
经过
auto layer = SplashScene::create();