cocos2d-x v3.0新特性及使用
八月份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 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
强大枚举类型更新:
| 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.
Removed Objective-C patterns
移除了所有Object-c模式,删除了CC前辍使用纯C++函数
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... | 
v2.1 methods are still available, but they were tagged as deprecated.
getters
Getters now use the get prefix.
Examples:
| v2.1 | v3.0 | 
| node->boundingBox() | node->getBoundingBox() | 
| sprite->nodeToParentTransform() | sprite->getNodeToParentTransform() | 
| etc... | 
And getters were also tagged as const in 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 | 
Global functions changed example
 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 | 
--------------------------------------------------------------------------------------------------------
cocos2d-x v3.0新特性及使用的更多相关文章
- GitHub 桌面版 v3.0 新特性「GitHub 热点速览」
		新版本一般意味着更强的功能特性,比如 GitHub Desktop v3.0.虽然未发布新版本,但本周收录的 7 个开源项目颇有"新版"味.比如,破解(恢复)密码能力 Max 的 ... 
- 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性
		[索引页][源码下载] 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性 作者:weba ... 
- Servlet 3.0 新特性详解 (转载)
		原文地址:https://www.ibm.com/developerworks/cn/java/j-lo-servlet30/ Servlet 3.0 新特性概述 Servlet 3.0 作为 Jav ... 
- Vue3.0新特性
		Vue3.0新特性 Vue3.0的设计目标可以概括为体积更小.速度更快.加强TypeScript支持.加强API设计一致性.提高自身可维护性.开放更多底层功能. 描述 从Vue2到Vue3在一些比较重 ... 
- C++ 2.0新特性
		C++ standard之演化 C++ 98(1.0) C++ 03(TR1, technical Report 1) // 一个实验性的版本 C++ 11(2.0) C++ 14 此次记录涵盖了C+ ... 
- 浅谈Tuple之C#4.0新特性那些事儿你还记得多少?
		来源:微信公众号CodeL 今天给大家分享的内容基于前几天收到的一条留言信息,留言内容是这样的: 看了这位网友的留言相信有不少刚接触开发的童鞋们也会有同样的困惑,除了用新建类作为桥梁之外还有什么好的办 ... 
- Java基础和JDK5.0新特性
		Java基础 JDK5.0新特性 PS: JDK:Java Development KitsJRE: Java Runtime EvironmentJRE = JVM + ClassLibary JV ... 
- Visual Studio 2015速递(1)——C#6.0新特性怎么用
		系列文章 Visual Studio 2015速递(1)——C#6.0新特性怎么用 Visual Studio 2015速递(2)——提升效率和质量(VS2015核心竞争力) Visual Studi ... 
- Atitit dsl exer v3 qb3 新特性
		Atitit dsl exer v3 qb3 新特性 /atiplat_cms/src/com/attilax/dsl/DslParser.java V3 支持typeed参数,与简化的notyp参数 ... 
随机推荐
- appium--【Mac】提示报错“could not launch WebDriverAgentRunner..........."
			运行appium WebDriverAgentLib和WebDriverAgentRunner都编译到真机运行成功,未在桌面生成一个没图标的WebDriverAgentRunner 连接并选择自己 ... 
- jmeter----计数器
			在测试过程中,往往需要一些有一定规则的数字,这个时候,可以使用配置元件中的计数器去实现. 一.界面显示 二.配置说明 1.名称:标识 2.注释:备注 3.启动:是指计数器开始的值 4.递增:每次增加的 ... 
- thinkphp5.1使用phpstudy隐藏index.php
			apache的重写规则如下: <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on R ... 
- Qt 下载列表地址
			每次下载Qt总是找好长时间,收藏一下地址 Qt 下载列表地址 https://www.qt.io/download-open-source/#section-9 教育网镜像下载 http://mirr ... 
- virtualenv    python的虚拟环境
			官网:https://virtualenv.pypa.io/en/stable/userguide/ virtualenv通过创建独立Python开发环境的工具, 来解决依赖.版本问题 基本使用: d ... 
- xpath语法规则
			参考w3cschool教程 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历. XPath 是 W3C XSLT 标准的主要元素,并且 XQ ... 
- 找到最大或最小的N个元素---heapq模块
			堆排序heapq的用法 基本用法: 复杂数据结构: # coding=utf- # example.py # Example of using heapq to find the N smallest ... 
- Java Hibernate和.Net EntityFramework   如何在提交事务之前 就拿到需要新增实体的Id
			在Hibernate中很容易做到这一点,因为hibernate在事务commit之前 还有一个save方法,这个save方法就可以持久化并且拿到Id. 但是EF并不可以呀,EF是将对象标记为新增状态 ... 
- Codeforces 722C(并查集 + 思维)
			本文链接:http://www.cnblogs.com/Ash-ly/p/5932712.html 题目链接:http://codeforces.com/problemset/problem/722/ ... 
- [Codeforces19D]Points 线段树
			大致题意: 给出n个询问,每次询问有三种: 1.往平面上加一个点 2.删除平面上的一个点 3.给出一个点p,查询平面上某点q,使得q.x>p.x且q.y>p.y,输出x轴坐标最小的q,若有 ... 
