上一篇解释了如何编译成功HelloCpp,现在说一下场景切换,如何使用按钮,进行场景切换!!!(代码量没多少,书上有一步也没有说明,害死人啊,一下午就这么没了!!!)笔者想练习下场景切换。现在说下,GameScene.h文件GameScene.cpp文件当中其代码如下:
GameScene.h文件如下:
#ifndef __GAMASCENE__H#define __GAMASCENE__H#include "cocos2d.h"class CGameScene : public 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(CGameScene);};#endif // __HELLOWORLD_SCENE_H__GameScene.cpp文件如下:
#include "GameScene.h"#include "AppMacros.h"USING_NS_CC; CCScene* CGameScene::scene(){ // 'scene' is an autorelease object CCScene *scene = CCScene::create(); // 'layer' is an autorelease object CGameScene *layer = CGameScene::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene;}bool CGameScene::init(){ if(!cclayer::init()) { return false; } CCSize visibleSize=CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin=CCDirector::sharedDirector()->getVisibleOrigin(); cclabelTTF*pLabel=cclabelTTF::create("周建业的游戏","Arial",Title_Font_SIZE); pLabel->setposition(ccp(origin.x+visibleSize.wIDth/2,origin.y+visibleSize.height-pLabel->getContentSize().height)); this->addChild(pLabel,1); CCSprite* pSprite=::CCSprite::create("new.jpg"); 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;}这个代码经过笔者无数次检测都没有问题,但是一直出现下述错误
D:/AndroID/androID-ndk-r9d-windows-x86/androID-ndk-r9d/toolchains/arm-linux-androIDeabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androIDeabi/4.6/../../../../arm-linux-androIDeabi/bin/ld.exe: ./obj/local/armeabI/ObJs/hellocpp_shared/__/__/Classes/HelloWorldScene.o: in function HelloWorld::menuCloseCallback(cocos2d::CCObject*):jni/../../Classes/HelloWorldScene.cpp:100: error: undefined reference to 'CGameScene::scene()'
collect2: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libhellocpp.so] Error 1
原来到最后还需要修改AndroID.mk文件,该文件中有了编译选项,在里面的
LOCAL_SRCS中添加我们自行添加的GameScene.cpp文件
LOCAL_SRC_fileS := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp \ ../../Classes/GameScene.cpp \
总结以上是内存溢出为你收集整理的cocos2d 场景切换 unreferenced!!!!错误全部内容,希望文章能够帮你解决cocos2d 场景切换 unreferenced!!!!错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)