cocos2dx2.0升级为3.0一些常见变化纪录

cocos2dx2.0升级为3.0一些常见变化纪录,第1张

概述 原文链接:http://www.blogjava.net/dongbule/archive/2013/12/27/408140.html 最近接手项目从cocos2dx 2.0 升级为 3.0 ,至于为什么要升级我也弄不清楚,只感觉3.0是要摆脱cocos2d-iphone的身影,这是要作死的态度吗,没时间去了解3.0的核心发生了神马变化,只为了从cocos2dx2.0经常适应到3.0做了一 

原文链接:http://www.blogjava.net/dongbule/archive/2013/12/27/408140.html


最近接手项目从cocos2dx 2.0 升级为 3.0 ,至于为什么要升级我也弄不清楚,只感觉3.0是要摆脱cocos2d-iphone的身影,这是要作死的态度吗,没时间去了解3.0的核心发生了神马变化,只为了从cocos2dx2.0经常适应到3.0做了一些纪录,以便查阅和方便正在从2.0到3.0的朋友。

1.去CC 之前2.0的CC**,把CC都去掉,基本的元素都是保留的
2.0CCSprite  CCCallFunc CCNode ..3.0Sprite CallFunc Node ..
2.cc***结构体改变
2.0        ccp(x,y)        ccpAdd(p1,p2)ccpsubccpMultccpLength(p)ccpDot(p1,p2);ccc3()ccc4()ccwHITECCPointZeroCCSizeZero2.0Point(x,y)p1+p2;p1-p2p1*p2p.getLength()p1.dot(p2)color3B()color4B()color3B::WHITEPoint::ZEROSize:ZERO
3.shared***改变
2.0CCSize winSize = CCDirector::sharedDirector()->getWinSize();SpriteFrameCache::sharedSpriteFrameCache()AnimationCache::sharedAnimationCache()NotificationCenter::sharednotificationCenter()…3.0Size size = Director::getInstance()->getWinSize();SpriteFrameCache::getInstance()AnimationCache::getInstance()NotificationCenter::getInstance()…

4.POD类别 使用const为Point,Size,Rect进行常量修饰
2.0voID setPoint(CCPoint p)3.0voID setPoint(const Point& p)

5.点触事件 此部分全面更新采用Event Listener
auto dispatcher = Director::getInstance()->getEventdispatcher();auto touchListener = EventListenertouchOneByOne::create();touchListener->ontouchBegan = CC_CALLBACK_2(FBMainScene::ontouchBegan,this);touchListener->ontouchmoved = CC_CALLBACK_2(FBMainScene::ontouchmoved,this);touchListener->ontouchended = CC_CALLBACK_2(FBMainScene::ontouchended,this);dispatcher->addEventListenerWithSceneGraPHPriority(touchListener,this);bool FBMainScene::ontouchBegan(touch *touch,Event *pEvent){    cclOG("ontouchBegan");    Point point = this->convertToWorldspace(this->converttouchToNodeSpace(touch));    return true;}voID FBMainScene::ontouchmoved(touch *touch,Event *pEvent){    cclOG("ontouchmoved");}voID FBMainScene::ontouchended(touch *touch,Event *pEvent){    cclOG("ontouchended");}//获得触点的方法也发生了改变:Point point = this->convertToWorldspace(this->converttouchToNodeSpace(touch));//dispatcher控制方法:dispatcher->addEventListener…dispatcher->removeEventListener(Listener);dispatcher->removeAllListeners();

6.CC_CALLBACK_* CC_CALLBACK_0 CC_CALLBACK_1 CC_CALLBACK_2 CC_CALLBACK_3 回调函数,分别携带不同的参数,方便
2.0CcmenuItemFont *item = CcmenuItemFont::create("返回上个场景",this,menu_selector(GameScene::backScene));3.0MenuItemFont *item = MenuItemLabel::create("返回上个场景",CC_CALLBACK_1(GameScene::backScene,this));// new callbacks based on C++11#define CC_CALLBACK_0(__selector__,__target__,) std::bind(&__selector__,##__VA_ARGS__)#define CC_CALLBACK_1(__selector__,std::placeholders::_1,##__VA_ARGS__)#define CC_CALLBACK_2(__selector__,std::placeholders::_2,##__VA_ARGS__)#define CC_CALLBACK_3(__selector__,std::placeholders::_3 ##__VA_ARGS__)

7.使用"Function"对象
CallFunc::create([&](){        Sprite *sprite = Sprite::create("s");        this->addChild(sprite);});

8.使用clone代替copy
2.0CCMoveBy *action = (CCMoveBy*) move->copy();action->autorelease();3.0action = move->clone();不需要autorelease,在clone已经实现。

9.Physics Integration 物理引擎 暂无使用,Box2d 在 3.0中可以延续使用 在3.0的Physics中需要定义 PhysicsWorld,PhysicsBody,PhysiCSShape,PhysicsJoint 等,于Box2d相仿,使用前需要定义CC_USE_PHYSICS ……继续等待补充

----------------------------------------

by 陈于喆
QQ:34174409
Mail: dongbule@163.com
 总结

以上是内存溢出为你收集整理的cocos2dx2.0升级为3.0一些常见变化纪录全部内容,希望文章能够帮你解决cocos2dx2.0升级为3.0一些常见变化纪录所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1046967.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存