【关于cocos2dx】一个很初级的问题,但是困扰我很久了

我是初学。问的问题可能很幼稚。大家耐心一点哈。

下面是我自己定义的一个场景类头文件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头文件呢?

不知道我的描述是否清楚,看懂的希望能给我解释一下哈。这里感激不尽!

没有用createScene?根据提供的信息还是无法断定问题出在哪里,能给点截图或多一点源码最好

只能猜测,是不是你的文件没有添加到项目中啊

public CCLayer 公友继承你试试

楼主, 你自定义的类文件有没有add到项目里→_→

很有可能是创建是没有添加到项目中,把那个文件delete掉,然后重新添加。

你SecondScene文件放的位置不对吧

你SecondScene文件放的位置不对吧

检查下是否在其它地方定义了__SECOND_SCENE_H__而导致SecondScene实际上没定义。

VS开发的话新建类默认是在proj.win32文件夹下,你复制到Classes里就好了,Xcode的话太久没用忘记了,估计也是路径问题,你去文件夹里看看

你SecondScene文件放的位置不对吧