我是初学。问的问题可能很幼稚。大家耐心一点哈。
下面是我自己定义的一个场景类头文件SecondScene.h
#ifndef SECOND_SCENE_H
#define SECOND_SCENE_H
#include “cocos2d.h”
class SecondScene:cocos2d::CCLayer
{
public:
// Here’s a difference. Method ‘init’ in cocos2d-x returns bool, instead of returning ‘id’ in cocos2d-iphone
virtual bool init();
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* scene();
// a selector callback
// void menuCloseCallback(CCObject* pSender);
// implement the "static node()" method manually
CREATE_FUNC(SecondScene);
};
#endif // HELLOWORLD_SCENE_H
下面这个是我自己定义的场景类cpp文件
主要就是创建一个标签在屏幕上显示出来
#include"SecondScene.h"
USING_NS_CC;
CCScene* SecondScene::scene()
{
CCScene* scene=CCScene::create();
SecondScene* layer=SecondScene::create();
scene->addChild(layer);
return scene;
}
bool SecondScene::init()
{
CCLabelTTF* label=CCLabelTTF::create(“nihao”,“Arial”,40);
label->setPosition(ccp(200,200));
this->addChild(label);
return true;
}
问题来了,我的目的就是要让单击原来的HelloWorld场景的退出按钮时能切换到我自己定义的场景。可是当我在
HelloWorldScene.cpp文件的
HelloWorld::menuCloseCallback(CCObject* pSender)函数中输出这样一句话时候
CCDirector::sharedDirector()->replaceScene(SecondScene::scene ());
报错SecondScene是无法识别的类
我想可能是没有加SecondScene.h的头文件,于是在HelloWorld.cpp文件中加了。但是又
报错为无法打开源文件SecondScene.h头文件
纳闷为什么能包含HelloWorldScene.h头文件,却不能包含自己定义的SecondScene.h头文件呢?
不知道我的描述是否清楚,看懂的希望能给我解释一下哈。这里感激不尽!