
转自:http://www.cnblogs.com/jiangu66/archive/2013/08/09/3249354.HTML
八月份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:
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 anstd::function<voID()> CallFuncNcan be created with anstd::function<voID(Node*)> CallFuncNDandCallFuncOwere removed since it can be created with simulated withCallFuncNandCallFunc. See ActionsTest.cpp for more examples MenuItemsupportsstd::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 |
The old values can still be used,but are not deprecated.
overrIDe 当虚函数被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.12CCMoveBy *action = (CCMoveBy*) move->copy();3action->autorelease();45// v3.06// No need to do autorelease,no need to do casting.7auto action = move->clone();Singletons use getInstance() and destroyInstance()
All singletons usegetInstance()anddestroyInstance()(if applicable) to get and destroy the instance.
Examples:
| Director->getInstance() | |
| CCDirector->endDirector() | Director->destroyInstance() |
| etc... |
v2.1 methods are still available,but they were tagged as deprecated.
getters
Getters Now use thegetprefix.
node->boundingBox()
constin their declaration. Example: 2virtual float getScale();345float getScale() const;
POD types
Methods that were receiving POD types as arguments (eg:TexParams,Point,250)">Size,etc.) are being passed asconstreference.
voID setTexParameters(ccTexParams* texParams);voID setTexParameters(const ccTexParams& texParams);
Misc API Changes ccTypes.h
Removeccprefix 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 |
Global functions changed example
1 2// in v2.1 3cccolor3B color3B = ccc3(0,0); 4ccc3BEqual(color3B,1,207)">1)); 5cccolor4B color4B = ccc4(0); 6cccolor4F color4F = ccc4f( 7color4F = ccc4FFromccc3B(color3B); 8color4F = ccc4FFromccc4B(color4B); 9ccc4FEqual(color4F,ccc4F(10color4B = ccc4BFromccc4F(color4F);1112color3B = ccwHITE;1314// in v3.015color3B color3B = color3B(16color3B.equals(color3B(17color4B color4B = color4B(18color4F color4F = color4F(19color4F = color4F(color3B);20color4F = color4F(color4B);21color4F.equals(color4F(22color4B = color4B(color4F);2324color3B = color3B::WHITE;deprecated functions and global variables
| new name | ||||
| ccp | Point | |||
| ccpNeg | Point::- | |||
| ccpAdd | Point::+ | |||
| ccpsub | 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 | ccpAngleSigned | ccpAngle | ccpRotateByAngle | Point::rotateByAngle |
| ccplineInersect | Point::islineIntersect | |||
| ccpsegmentIntersect | Point::isSegmentIntersect | |||
| ccpIntersectPoint | Point::getIntersectPoint | |||
| CCPointMake | CCSizeMake | Size::Size | ||
| CCRectMake | Rect::Rect | |||
| PointZero | 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() | ccc4FFromccc4B() | ccc4BFromccc4F() | ccc4FEqual() | color4F::equals() |
| ccwHITE | color3B::WHITE | |||
| ccYELLOW | color3B::YELLOW | |||
| ccBLUE | color3B::BLUE | |||
| 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文件夹中找到创建好的项目 关于项目的选择: 图示: 红包点选就可以选择对应运行平台 总结
以上是内存溢出为你收集整理的cocos2d-x v3.0新特性及使用全部内容,希望文章能够帮你解决cocos2d-x v3.0新特性及使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)