cocos2d-x v3.0新特性及使用
2015-10-31 23:51
483 查看
八月份cocos2d-x官网发布了v3.0版本,这次更新的内容特别多,包括2dx的架构以及使用
总得来说,给开发者带来了很大的便利:
运行环境需求:
Android 2.3 or newer
iOS 5.0 or newer
OS X 10.7 or newer
Windows (which version?)
Linux Ubuntu 12.04 (or newer)
编译环境需求:
Xcode 4.6 (for iOS or Mac)
gcc 4.7 for Linux or Android. For Android ndk-r8e or newer is required.
Visual Studio 2012 (for Windows)
重要更新内容:
Replace Objective-C patters with C++ (C++11) patterns and best practices
Improve Labels
Improve renderer
其中C++ 11 新特性:
A subset of C++11 features are being used in cocos2d-x:
strongly typed enums, for most of the cocos2d-x enums and constants
removed since it can be created with simulated with
See ActionsTest.cpp for more examples
callbacks
强大枚举类型更新:
Examples:
The old values can still be used, but are not deprecated.
override
当虚函数被override关健字修饰时,子类实现时有override标记
移除了所有Object-c模式,删除了CC前辍使用纯C++函数
对于类的使用改变:
2dx-3.0 两也不用使用using coco2d namespace
code will crash.
Example:
All singletons use
applicable) to get and destroy the instance.
Examples:
v2.1 methods are still available, but they were tagged as deprecated.
Getters now use the
Examples:
And getters were also tagged as
v2.1 methods are still available, but they were tagged as deprecated.
Methods that were receiving POD types as arguments (eg:
etc.) are being passed as
Example:
Remove cc prefix for structure names in ccTypes.h, move global functions into static member functions, and move global constants into const static member variables.
Global functions changed example
--------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
创建新项目:
v3.0不再需要创建Xcode模版,使用create-multi-platform-projects.py来创建一个跨平台的项目,使用方法
1,cd 到2dx根目录,MAC平台使用./create-multi-platform-projects.py 然后提示:
-bash: ./create-multi-platform-projects.py: /usr/bin/evn: bad interpreter: No such file or directory
没关系,我们打开.py文件,发现其实引用的是tools/project_creator/create_project.py 这文件
2,我们再cd 到project_creator文件中,使用 ./create_project.py -p <PROJECT_NAME> -k <PACKAGE_NAME> -l <cpp|lua|javascript>
3,这样我们就可以在2dx的projects文件夹中找到创建好的项目
关于项目的选择:
图示:
红包点选就可以选择对应运行平台
总得来说,给开发者带来了很大的便利:
运行环境需求:
Android 2.3 or newer
iOS 5.0 or newer
OS X 10.7 or newer
Windows (which version?)
Linux Ubuntu 12.04 (or newer)
编译环境需求:
Xcode 4.6 (for iOS or Mac)
gcc 4.7 for Linux or Android. For Android ndk-r8e or newer is required.
Visual Studio 2012 (for Windows)
重要更新内容:
Replace Objective-C patters with C++ (C++11) patterns and best practices
Improve Labels
Improve renderer
其中C++ 11 新特性:
A subset of C++11 features are being used in cocos2d-x:
std::function, including lambda objects for callbacks
strongly typed enums, for most of the cocos2d-x enums and constants
std::threadfor threading
overridecontext keyword, for overriden methods
st std::function
CallFunccan be created with an
std::function<void()>
CallFuncNcan be created with an
std::function<void(Node*)>
CallFuncNDand
CallFuncOwere
removed since it can be created with simulated with
CallFuncNand
CallFunc.
See ActionsTest.cpp for more examples
MenuItemsupports
std::function<void(Node*)>as
callbacks
强大枚举类型更新:
Examples:
v2.1 | v3.0 |
kCCTexture2DPixelFormat_RGBA8888 | Texture2D::PixelFormat::RGBA8888 |
kCCDirectorProjectionCustom | Director::Projection::CUSTOM |
ccGREEN | Color3B::GREEN |
CCPointZero | Point::ZERO |
CCSizeZero | Size::ZERO |
当虚函数被override关健字修饰时,子类实现时有override标记
Removed Objective-C patterns
移除了所有Object-c模式,删除了CC前辍使用纯C++函数对于类的使用改变:
2dx-3.0 两也不用使用using coco2d namespace
clone() instead of copy()
clone()returns an autoreleased version of the copy.
copy()is no longer supported. If you use it, it will compile, but the
code will crash.
Example:
1// v2.1 2CCMoveBy *action = (CCMoveBy*) move->copy(); 3action->autorelease(); 4 5// v3.0 6// No need to do autorelease, no need to do casting. 7auto action = move->clone();
Singletons use getInstance() and destroyInstance()
All singletons use getInstance()and
destroyInstance()(if
applicable) to get and destroy the instance.
Examples:
v2.1 | v3.0 |
CCDirector->sharedDirector() | Director->getInstance() |
CCDirector->endDirector() | Director->destroyInstance() |
etc... |
getters
Getters now use the getprefix.
Examples:
v2.1 | v3.0 |
node->boundingBox() | node->getBoundingBox() |
sprite->nodeToParentTransform() | sprite->getNodeToParentTransform() |
etc... |
constin their declaration. Example:
1// v2.1 2virtual float getScale(); 3 4// v3.0 5virtual float getScale() const;
v2.1 methods are still available, but they were tagged as deprecated.
POD types
Methods that were receiving POD types as arguments (eg: TexParams,
Point,
Size,
etc.) are being passed as
constreference.
Example:
1// v2.1 2void setTexParameters(ccTexParams* texParams); 3 4// v3.0 5void setTexParameters(const ccTexParams& texParams);
Misc API Changes
ccTypes.h
Remove cc prefix for structure names in ccTypes.h, move global functions into static member functions, and move global constants into const static member variables.structure name before changing | structure name after changing |
ccColor3B | Color3B |
ccColor4B | Color4B |
ccColor4F | Color4F |
ccVertex2F | Vertex2F |
ccVertex3F | Vertex3F |
ccTex2F | Tex2F |
ccPointSprite | PointSprite |
ccQuad2 | Quad2 |
ccQuad3 | Quad3 |
ccV2F_C4B_T2F | V2F_C4B_T2F |
ccV2F_C4F_T2F | V2F_C4F_T2F |
ccV3F_C4B_T2F | V3F_C4B_T2F |
ccV2F_C4B_T2F_Triangle | V2F_C4B_T2F_Triangle |
ccV2F_C4B_T2F_Quad | V2F_C4B_T2F_Quad |
ccV3F_C4B_T2F_Quad | V3F_C4B_T2F_Quad |
ccV2F_C4F_T2F_Quad | V2F_C4F_T2F_Quad |
ccBlendFunc | BlendFunc |
ccT2F_Quad | T2F_Quad |
ccAnimationFrameData | AnimationFrameData |
1 2// in v2.1 3ccColor3B color3B = ccc3(0, 0, 0); 4ccc3BEqual(color3B, ccc3(1, 1, 1)); 5ccColor4B color4B = ccc4(0, 0, 0, 0); 6ccColor4F color4F = ccc4f(0, 0, 0, 0); 7color4F = ccc4FFromccc3B(color3B); 8color4F = ccc4FFromccc4B(color4B); 9ccc4FEqual(color4F, ccc4F(1, 1, 1, 1)); 10color4B = ccc4BFromccc4F(color4F); 11 12color3B = ccWHITE; 13 14// in v3.0 15Color3B color3B = Color3B(0, 0, 0); 16color3B.equals(Color3B(1, 1, 1)); 17Color4B color4B = Color4B(0, 0, 0, 0); 18Color4F color4F = Color4F(0, 0, 0, 0); 19color4F = Color4F(color3B); 20color4F = Color4F(color4B); 21color4F.equals(Color4F(1, 1, 1, 1)); 22color4B = Color4B(color4F); 23 24color3B = Color3B::WHITE;
deprecated
functions and global variables
old name | new name |
ccp | Point |
ccpNeg | Point::- |
ccpAdd | Point::+ |
ccpSub | Point::- |
ccpMult | Point::* |
ccpMidpoint | Point::getMidpoint |
ccpDot | Point::dot |
ccpCrosss | Point::cross |
ccpPerp | Point::getPerp |
ccpRPerp | Point::getRPerp |
ccpProject | Point::project |
ccpRotate | Point::rotate |
ccpUnrotate | Point::unrotate |
ccpLengthSQ | Point::getLengthSq() |
ccpDistanceSQ | Point::getDistanceSq |
ccpLength | Point::getLength |
ccpDistance | Point::getDistance |
ccpNormalize | Point::normalize |
ccpForAngle | Point::forAngle |
ccpToAngle | Point::getAngle |
ccpClamp | Point::getClampPoint |
ccpFromSize | Point::Point |
ccpCompOp | Point::compOp |
ccpLerp | Point::lerp |
ccpFuzzyEqual | Point::fuzzyEqual |
ccpCompMult | Point::Point |
ccpAngleSigned | Point::getAngle |
ccpAngle | Point::getAngle |
ccpRotateByAngle | Point::rotateByAngle |
ccpLineInersect | Point::isLineIntersect |
ccpSegmentIntersect | Point::isSegmentIntersect |
ccpIntersectPoint | Point::getIntersectPoint |
CCPointMake | Point::Point |
CCSizeMake | Size::Size |
CCRectMake | Rect::Rect |
PointZero | Point::ZERO |
SizeZero | Size::ZERO |
RectZero | Rect::ZERO |
TiledGrid3DAction::tile | TiledGrid3DAction::getTile |
TiledGrid3DAction::originalTile | TiledGrid3DAction::getOriginalTile |
TiledGrid3D::tile | TiledGrid3D::getTile |
TiledGrid3D::originalTile | TiledGrid3D::getOriginalTile |
Grid3DAction::vertex | Grid3DAction::getVertex |
Grid3DAction::originalVertex | Grid3DAction::getOriginalVertex |
Grid3D::vertex | Grid3D::getVertex |
Grid3D::originalVertex | Grid3D::getOriginalVertex |
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 |
ccc3() | Color3B() |
ccc3BEqual() | Color3B::equals() |
ccc4() | Color4B() |
ccc4FFromccc3B() | Color4F() |
ccc4f() | Color4F() |
ccc4FFromccc4B() | Color4F() |
ccc4BFromccc4F() | Color4B() |
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 |
kBlendFuncDisable | BlendFunc::BLEND_FUNC_DISABLE |
--------------------------------------------------------------------------------------------------------
创建新项目:
v3.0不再需要创建Xcode模版,使用create-multi-platform-projects.py来创建一个跨平台的项目,使用方法
1,cd 到2dx根目录,MAC平台使用./create-multi-platform-projects.py 然后提示:
-bash: ./create-multi-platform-projects.py: /usr/bin/evn: bad interpreter: No such file or directory
没关系,我们打开.py文件,发现其实引用的是tools/project_creator/create_project.py 这文件
2,我们再cd 到project_creator文件中,使用 ./create_project.py -p <PROJECT_NAME> -k <PACKAGE_NAME> -l <cpp|lua|javascript>
3,这样我们就可以在2dx的projects文件夹中找到创建好的项目
关于项目的选择:
图示:
红包点选就可以选择对应运行平台
相关文章推荐
- cocos 2dx 基于C++的 五子棋AI算法思想
- cocos2dx一路走来之<性能优化>
- Cocos适配带虚拟导航栏手机(HUAWEI 荣耀6 Plus)
- 【Cocos2dx】计时器的使用,计时器的嵌套,与在计时器中延时执行一段代码
- cocos2dx一路走来之<vs2013使用中遇到的问题>
- Cocos2d-x 基础元素
- cocos2dx一路走来之<API学习:数据存储UserDefault>
- Box2D 物理引擎---创建一个简单的模拟物理世界
- cocos2dx播放音乐
- cocos2dx 苹果5分辨率 适配错误
- cocos2d-x-3.4 无法打开包含文件extensions/ExtensionExport.h
- [置顶] vs 2015 编译cocos2dx 报错
- Cocos2d-x 3.0rc0 的Win32工程添加CocoStudio库
- 【Cocos2dx】利用导演类、场景类完成重新开始游戏、暂停游戏、关闭游戏功能
- cocos2dx一路走来之<window下打包apk>
- Cocos2d入门--3--向量的应用
- 【Cocos2d-x游戏开发】编译时出现 commands commence before first target
- cocos2d-x平台审核中遇到的openssl问题解决方案
- cocos2dx中.json和.plist以及.xml文件格式生成加载的不同
- cocos2dx java调用c++