cocos2d 场景切换 unreferenced!!!!错误

上一篇解释了如何编译成功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 \

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

世纪殇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值