错误'CCScene'未在Cocos2d-x中命名类型

时间:2014-01-22 16:12:28

标签: c++ cocos2d-x

我收到此错误'CCScene'未命名类型'类SceneManager'没有名为'createScene'的成员

我的代码如下。你能告诉我哪里错了吗?感谢

SceneManager.h

class SceneManager : public cocos2d::CCLayer
{
public:
    virtual bool init();  
    static cocos2d::CCScene* scene();
    CCScene* createScene(int sceneID);
};

SceneManager.cpp

CCScene* SceneManager::createScene(int sceneID){
    CCScene* pScene = NULL;

    switch (sceneID){
        case LOGO_SCENE:
        {
            pScene = CCScene::create();
            // LogoScene pScene = new LogoScene();
            break;
        }   
        default: break;
    }

    return pScene;
}

CCScene* SceneManager::scene(){
    CCScene *scene = CCScene::create();
    return scene;
}

bool SceneManager::init(){
    if (!CCLayer::init())
    {
        return false;
    }
    return true;
}

然后,我打电话给 AppDelegate.cpp

创建场景
...
// create a scene. it's an autorelease object
    SceneManager *pSceneManager = new SceneManager();
    CCScene *pScene = pSceneManager->createScene(LOGO_SCENE);

    // run
    pDirector->runWithScene(pScene);

1 个答案:

答案 0 :(得分:3)

我认为你忘了使用命名空间cocos2d

<强> SceneManager.h

class SceneManager : public cocos2d::CCLayer
{
public:
  virtual bool init();  
  static cocos2d::CCScene* scene();
  cocos2d::CCScene* createScene(int sceneID);
};

SceneManager.cpp,AppDelegate.cpp

为cocos2d-x类确保using namespace cocos2d;USING_NS_CC;或前置cocos2d::