常用类名改变
删除了CC前缀
CCAction
-> Action
CCAction
-> Point
CCPoint
-> Animation
CCAnimation
-> Sprite
CCSprite
-> Label
CCLabel
-> Menu
CCMenu
-> Ref
CCObject
-> Node
CCNode
-> Scene
CCScene
-> Layer
CCLayer
-> SpriteBatchNode
CCSpriteBatchNoe
-> TMXTiledMap
CCTMXTiledMap
-> ValueMap
CCDictionary
-> ValueVector
CCArray
-> Value
CCString
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__,__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__)
v2调用方法
CMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ActionsDemo::backCallback));
v3调用方法1
MenuItemImage *item1 = MenuItemImage::create(s_pPathB1, s_pPathB2, CC_CALLBACK_1(ActionsDemo::backCallback, this));
v3调用方法2
MenuItemImage *item1 = MenuItemImage::create(s_pPathB1, s_pPathB2, [=](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
逆时针旋转90度
Vect::cross
->
ccpPerp
顺时针旋转90度
Vect::getPerp
->
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部分函数对照表