把cocos2dx 2.2的项目移植到 cocos2dx 3.8

本文详细介绍了如何将Cocos2d-x 2.2项目的安卓编译环境升级至3.8版本,包括类名修改、触摸事件变更、选择函数调整等关键步骤,并提供了官方升级文档链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原因:要送个消消乐游戏给人,有个现成的cocos2dx 2.2项目,但搭建cocos2dx 2.2版本的安卓编译环境各种失败,于是就想升级到3.8,方便编译安卓apk包。


归纳变化如下

1 CC开头的类名,如果找不到,去掉CC


2 触摸事件变更。

覆盖ccTouchBegan,ccTouchMoved, ccTouchEnded,ccTouchCancelled触摸函数修改为事件监听

        EventListenerTouchOneByOne *touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(GameLayer::ccTouchBeganCallback, this);
touchListener->onTouchMoved = CC_CALLBACK_2(GameLayer::ccTouchMovedCallback, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);


3 select 改为CC_CALLBACK_*

    CCMenuItemImage *playMenuItem = CCMenuItemImage::create(PLAY_IMAGE, PLAY_IMAGE_PRESSED, this,menu_selector(PlayMenu::play));

=>  CCMenuItemImage *playMenuItem = CCMenuItemImage::create(PLAY_IMAGE, PLAY_IMAGE_PRESSED, CC_CALLBACK_0(PlayMenu::play, this));


4 宏变更

ccBLACK  =》Color3B::BLACK


5 时间接口变更

            struct cc_timeval now;
            CCTime::gettimeofdayCocos2d(&now, NULL);

=》                 struct timeval now;
gettimeofday(&now, NULL);


3 如果增减.h .cpp 注意修改安卓下的  Android.mk文件包含,

LOCAL_SRC_FILES :

LOCAL_C_INCLUDES :



附上官方升级文档:

http://www.cocos2d-x.org/wiki/User_Tutorial-CPP_Migration_from_v2_2_*_to_v3_0

C++ MIGRATION FROM V2 2 * TO V3 0

Cocos Creator模拟砸金蛋3d旋转效果 | 附代码egg.zip // Learn TypeScript: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class Game extends cc.Component { @property Count: number = 5; @property(cc.Prefab) prefab: cc.Prefab = null; @property(cc.Node) nodeParent: cc.Node = null; private mEggs: cc.Node[] = []; // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { } // update (dt) {} onClick(event, data){ switch(data){ case &#39;add&#39;:{ this.addEggs(); break; } case &#39;move&#39;:{ this.moveEggs(); break; } case &#39;stop&#39;:{ this.stopMoveEggs(); break; } } } addEggs(){ if(this.Count <= 0){ return; } this.mEggs = []; const N = 360 / this.Count; for(let i = 0; i < this.Count; i++){ let egg = cc.instantiate(this.prefab); let js = egg.getComponent(&#39;Egg&#39;); js.setRadian(i * N * Math.PI / 180); js.updatePos(); egg.parent = this.nodeParent; this.mEggs.push(egg); } } moveEggs(){ for(let i = 0; i < this.mEggs.length; i++){ this.mEggs[i].getComponent(&#39;Egg&#39;).setMove(true); } } stopMoveEggs(){ for(let i = 0; i < this.mEggs.length; i++){ this.mEggs[i].getComponent(&#39;Egg&#39;).setMove(false); } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值