日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【cocos2d-x】2.0升级为3.0一些常见变化纪录

發布時間:2023/12/9 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【cocos2d-x】2.0升级为3.0一些常见变化纪录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.去CC

之前2.0的CC**,把CC都去掉,基本的元素都是保留的

2.0
CCSprite??CCCallFunc?CCNode?..
3.0
Sprite?CallFunc?Node?..


2.cc***結構體改變

2.0????????
ccp(x,y)????????
ccpAdd(p1,p2)
ccpSub
ccpMult
ccpLength(p)
ccpDot(p1,p2);
ccc3()
ccc4()
ccWHITE
CCPointZero
CCSizeZero


2.0
Point(x,y)
p1+p2;
p1-p2
p1*p2
p.getLength()
p1.dot(p2)
Color3B()
Color4B()
Color3B::WHITE
Point::ZERO
Size:ZERO


3.shared***改變

2.0
CCSize?winSize?=?CCDirector::sharedDirector()->getWinSize();
SpriteFrameCache::sharedSpriteFrameCache()
AnimationCache::sharedAnimationCache()
NotificationCenter::sharedNotificationCenter()


3.0
Size?size?=?Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()
AnimationCache::getInstance()
NotificationCenter::getInstance()


4.POD類別

使用const為Point,Size,Rect進行常量修飾

2.0
void?setPoint(CCPoint?p)
3.0
void?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.0
CCMenuItemFont?*item?=?CCMenuItemFont::create("返回上個場景",?this,?menu_selector(GameScene::backScene));
3.0
MenuItemFont?*item?=?MenuItemLabel::create("返回上個場景",?CC_CALLBACK_1(GameScene::backScene,?this));

//?new?callbacks?based?on?C++11
#define?CC_CALLBACK_0(__selector__,__target__,?
)?std::bind(&__selector__,__target__,?##__VA_ARGS__)
#define?CC_CALLBACK_1(__selector__,__target__,?
)?std::bind(&__selector__,__target__,?std::placeholders::_1,?##__VA_ARGS__)
#define?CC_CALLBACK_2(__selector__,__target__,?
)?std::bind(&__selector__,__target__,?std::placeholders::_1,?std::placeholders::_2,?##__VA_ARGS__)
#define?CC_CALLBACK_3(__selector__,__target__,?
)?std::bind(&__selector__,__target__,?std::placeholders::_1,?std::placeholders::_2,?std::placeholders::_3?##__VA_ARGS__)


7.使用"Function"對象

CallFunc::create([&](){
????????Sprite?*sprite?=?Sprite::create("s");
????????this->addChild(sprite);
});


8.使用clone代替copy

2.0
CCMoveBy?*action?=?(CCMoveBy*)?move->copy();
action->autorelease();
3.0
action?=?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

?

轉載于:https://blog.51cto.com/kenkao/1431110

總結

以上是生活随笔為你收集整理的【cocos2d-x】2.0升级为3.0一些常见变化纪录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。