Я создаю игру на основе уровня. Трудно переопределить SVG файл на другом уровне.
Вот кодирование,
helloworld.cpp
const char* HelloWorld::SVGFileName() //virtual function
{
return NULL;
}
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *game = HelloWorld::create();
GameHUD *hud = GameHUD::HUDWithGameNode(game);
game->hud_ = hud;
scene->addChild(game);
scene->addChild(hud, 10);
return scene;
}
level1.h
class CC_DLL level1: public HelloWorld
{
public:
level1();
~level1();
const char* SVGFileName();
void addBodyNode(BodyNode* node,int zOrder);
void initGraphics();
};
level1.cpp
const char* level1::SVGFileName()
{
CCLog("LevelSVG: level: override me");
return ("test3.svg");
}
SelectLevelScene.cpp
void SelectLevelScene::level0()
{
CCDirector::sharedDirector()->replaceScene(level1::scene());
}
Моя проблема в том,
Я не могу переопределить функцию SVGFileName() в level1.cpp. Есть ли какие-либо проблемы в моем коде?
Любая идея исправить это?
Вы возвращаете const char *, созданный в локальной области функций. Это означает, что как только функция вернет возвращаемый указатель, это мусор.
Вместо этого вы должны вернуть std :: string.