0

我正在创建基于级别的游戏。很难覆盖不同级别的 SVG 文件。

这是编码,

你好世界.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;
 }

级别1.h

 class CC_DLL level1: public HelloWorld
 {
 public:
   level1();
   ~level1();
    const char* SVGFileName();
    void addBodyNode(BodyNode* node,int zOrder);
    void initGraphics();
 };

一级.cpp

 const char* level1::SVGFileName()
 {
    CCLog("LevelSVG: level: override me");
    return ("test3.svg");
 }

SelectLevelScene.cpp

void SelectLevelScene::level0()
{
   CCDirector::sharedDirector()->replaceScene(level1::scene());
}

我的问题是,

我无法覆盖 level1.cpp 中的函数 SVGFileName()。我的代码有问题吗?

有什么想法可以解决吗?

4

1 回答 1

1

您返回在函数的本地范围内创建的 const char*。这意味着一旦函数返回返回的指针就是垃圾。

您应该改为返回 std::string 。

于 2013-10-16T08:54:24.907 回答