cocos2d-x v2 升级到 v3

cocos2d-x v2 升级到 v3,第1张

概述常用类名改变 删除了CC前缀 CCAction CCAction -> Action CCPoint -> Point CCAnimation -> Animation CCSprite -> Sprite CCLabel -> Label CCMenu -> Menu CCObject -> Ref CCNode -> Node CCScene -> Scene CCLayer -> Layer 常用类名改变

删除了CC前缀
CCAction

CCAction -> Action
CCPoint -> Point
CCAnimation -> Animation
CCSprite -> Sprite
cclabel -> Label
Ccmenu -> Menu
CCObject -> Ref
CCNode -> Node
CCScene -> Scene
cclayer -> Layer
CCSpriteBatchNoe -> SpriteBatchNode
CCTMXTiledMap -> TMXTiledMap
CCDictionary -> ValueMap
CCArray -> ValueVector
CCString -> Value

CCString 改变

之前:

CCString* str = CCString::createWithFormat("%s.png","picture");

之后:

std::string str = StringUtils::format("%s.png","picture");
CCDictionary 改变

之前:

CCDictionary* dict = CCDictionary::createWithContentsOffile("name.pList");CCArray* arr = (CCArray*) dict->objectForKey("Levels");

之后:

std::string path = fileUtils::getInstance()->fullPathForfilename("name.pList");ValueMap dict = fileUtils::getInstance()->getValueMapFromfile(path);ValueVector arrLevels = dict.at("Levels").asValueVector();
CCArray 改变

改为标准的vector容器

CCArray* arr; -> ValueVector arr;
arr->addobject(sprite); -> arr.pushBack(sprite);
arr->removeObject(sprite); -> arr.eraSEObject(sprite);
arr->removeObjectAtIndex(i); -> arr.erase(i);
arr->objectAtIndex(i); -> arr.at(i);
arr->count(); -> arr.size();

触摸函数改变

cctouchBegan -> ontouchBegan
cctouchmoved -> ontouchmoved
cctouchended -> ontouchended

MenuItem 菜单 变化

ccMacros.h中宏定义

// 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__)

v2调用方法

cmenuItemImage *item1 = CcmenuItemImage::create(s_pPathB1,s_pPathB2,this,menu_selector(ActionsDemo::backCallback));

v3调用方法1

MenuItemImage *item1 = MenuItemImage::create(s_pPathB1,CC_CALLBACK_1(ActionsDemo::backCallback,this));

v3调用方法2

MenuItemImage *item1 = MenuItemImage::create(s_pPathB1,[=](Ref* sender){ //code here }););
全局单例类的改变

CCEGLVIEw::sharedOpenGLVIEw(); -> Director::getInstance()->getopenGLVIEw();
CCTextureCache::sharedTextureCache(); -> Director::getInstance()->getTextureCache();
CCNotificationCenter::sharednotificationCenter(); -> Director::getInstance()->getEventdispatcher();
Configuration::sharedConfiguration -> Configuration::getInstance
Configuration::purgeConfiguration -> Configuration::destroyInstance
Director::sharedDirector -> Director::getInstance
fileUtils::sharedfileUtils -> fileUtils::getInstance
fileUtils::purgefileUtils -> fileUtils::destroyInstance
EGLVIEw::sharedOpenGLVIEw -> EGLVIEw::getInstance
shadercache::sharedshadercache -> shadercache::getInstance
shadercache::purgeSharedshadercache -> shadercache::destroyInstance
AnimationCache::sharedAnimationCache -> AnimationCache::getInstance
AnimationCache::purgeSharedAnimationCache -> AnimationCache::destroyInstance
SpriteFrameCache::sharedSpriteFrameCache -> SpriteFrameCache::getInstance
SpriteFrameCache:: purgeSharedSpriteFrameCache -> SpriteFrameCache::destroyInstance
NotificationCenter::sharednotificationCenter -> NotificationCenter::getInstance
NotificationCenter:: purgeNotificationCenter -> NotificationCenter::destroyInstance
Profiler::sharedProfiler -> Profiler::getInstance
UserDefault::sharedUserDefault -> UserDefault::getInstance
UserDefault::purgeSharedUserDefault -> UserDefault::destroyInstance
Application::sharedApplication -> Application::getInstance
kBlendFuncdisable -> BlendFunc::BLEND_FUNC_disABLE

CCTime 改变

cc_timeval -> timeval
CCTime::gettimeofdayCocos2d -> gettimeofday
CCTime::timesubCocos2d -> getTimeDiffenceMS
事例:

static inline float getTimeDifferenceMS(timeval& start,timeval& end){ return ((((end.tv_sec - start.tv_sec)*1000.0f + end.tv_usec) - start.tv_usec) / 1000.0f);}
OpenGL 变化

一般做游戏不太涉及得到

CCGLProgram -> GLProgram
kCCUniformPMatrix_s -> GLProgram::UNIFORM_name_P_MATRIX
kCCUniformMVMatrix_s -> GLProgram::UNIFORM_name_MV_MATRIX
kCCUniformMVPMatrix_s -> GLProgram::UNIFORM_name_MVP_MATRIX
kCCUniformTime_s -> GLProgram::UNIFORM_name_TIME
kCCUniformSinTime_s -> GLProgram::UNIFORM_name_SIN_TIME
kCCUniformCosTime_s -> GLProgram::UNIFORM_name_COS_TIME
kCCUniformRandom01_s -> GLProgram::UNIFORM_name_RANDOM01
kCCUniformSampler_s -> GLProgram::UNIFORM_name_SAMPLER0
kCCUniformAlphaTestValue -> GLProgram::UNIFORM_name_Alpha_TEST_VALUE
kCCAttributenamecolor -> GLProgram::ATTRIBUTE_name_color
kCCAttributenameposition -> GLProgram::ATTRIBUTE_name_position
kCCAttributenameTexCoord -> GLProgram::ATTRIBUTE_name_TEX_COORD

函数对照 点 *** 作

ccp -> Vec2
点负数 ccpNeg -> Vect::negate or -
点相加 ccpAdd -> Vect::add or +
点相减 ccpsub -> Vect::subtract or -
点相乘 ccpMult -> Vect::*
点获得中点 ccpMIDpoint -> Vect::getMIDpoint
点积 ccpDot -> Vect::dot
叉积 ccpCrosss -> Vect::cross
逆时针旋转90度 ccpPerp -> Vect::getPerp
顺时针旋转90度 ccpRPerp -> Vect::getRPerp
投影 ccpProject -> Vect::project
ccpRotate -> Vect::rotate
ccpunrotate -> Vect::unrotate
长度未开方(点积) ccpLengthSQ -> Vect::getLengthSq
距离未开方 ccpdistanceSQ -> distanceSquared
长度 ccpLength -> getLength
距离 ccpdistance -> getdistance
取模 ccpnormalize -> normalize
从角度获得 ccpForAngle -> forAngle
转换为角度 ccpToAngle -> getAngle
ccpClamp -> getClampPoint
ccpFromSize ->
对x,y值进行函数处理 ccpCompOp -> compOp
两点构成直线上的点 ccpLerp -> lerp
模糊相等,两个点靠的足够近 ccpFuzzyEqual -> fuzzyEqual
ccpCompMult ->
和x轴的夹角或者和向量组成的夹角 ccpAngleSigned -> getAngle
同上 ccpAngle -> getAngle
旋转角度 ccpRotateByAngle -> rotateByAngle
线是否相交/四个点是否在一个平面 ccplineInersect -> islineIntersect
线段是否相交/四个点是否在一个平面 ccpsegmentIntersect -> isSegmentIntersect
获取线段交点 ccpIntersectPoint -> getIntersectPoint
CCPointMake ->

色彩 *** 作

ccc3() -> color3B()
ccc3BEqual() -> color3B::equals()
ccc4() -> color4B()
ccc4f() -> color4F()
ccc4FEqual() -> color4F::equals()
ccwHITE -> color3B::WHITE
ccYELLOW -> color3B::YELLOW
ccBLUE -> color3B::BLUE
ccGREEN -> color3B::GREEN
ccRED -> color3B::RED
ccmagenta -> color3B::magenta
ccBLACK -> color3B::BLACK
ccORANGE -> color3B::ORANGE
ccGRAY -> color3B::GRAY
ccc4FFromccc3B ->
ccc4FFromccc4B ->
ccc4BFromccc4F ->

用宏定义来查找API变化

全局搜索 CC_DEPRECATED_ATTRIBUTE

参考:
cocos2d-x v2 和 v3 对照手册
升级到Cocos2d-x v3.3-RC0总结Director的主线解析
cocos2dx2.x&3.x部分函数对照表

总结

以上是内存溢出为你收集整理的cocos2d-x v2 升级到 v3全部内容,希望文章能够帮你解决cocos2d-x v2 升级到 v3所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1070785.html

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

发表评论

登录后才能评论

评论列表(0条)

保存