0

使用 cocos2dx。创建新场景的 .h 和 .cpp 文件。但不能将其包含在主要场景中。 Error: Can't find source file "LevelSelect.h".

这是文件。水平选择.h

#ifndef LEVEL_SELECT_H_
#define LEVEL_SELECT_H_
#include "cocos2d.h"

/**
 * LevelSelector
 */
class LevelSelect : public cocos2d::CCScene
{
public:
    virtual bool init();  
    static cocos2d::CCScene* scene();
    void backCallback(CCObject* pSender);
    CREATE_FUNC(LevelSelect);
};
#endif

水平选择.cpp

#include "LevelSelect.h"
#include "AppMacros.h"

USING_NS_CC;

/**
 * Level Select scene
 */

CCScene* LevelSelect::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();

    // 'layer' is an autorelease object
    LevelSelect *layer = LevelSelect::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}
bool LevelSelect::init(){
        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    CCSize winSize = CCDirector::sharedDirector()->getWinSize(); 

CCSprite* pSprite = CCSprite::create("resources/main/01_bg.png");


pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    return true;
    }

尝试使用此代码切换场景

void MainMenu::menuNewGameCallback(CCObject* pSender){
     CCScene *pScene = LevelSelect::scene();
    CCDirector::sharedDirector()->replaceScene(pScene); 
}

什么是无效的?为什么我不能使用LevelSelect::scene();?如何正确编写场景并从主菜单调用它?

4

0 回答 0