Cocos2d-x 3.0 新特性体验(1)创建项目+运行sample+新特性内容
2014-03-05 14:02
489 查看
转自:http://www.2cto.com/kf/201401/273819.html
不得不说,cocos2d-x的版本更迭真是快,而最新的cocos2d-x v3.0 Beta版本中包含了许多新的特性和与之前2.x版本不同的内容,虽然说,目前3.0只是beta版本,但目前很多游戏已经采用这个3.0版本了,估计3.0的最终版本也会很快推出。
从创建项目开始了解一下这个最新的3.0版本的一些新特性吧!
一、创建项目(针对在mac os x中进行开发)
在前面我有一篇文章 点击打开链接 已经介绍过在 cocos2dx 2.2 版本中创建项目只能是在终端中进行,对于习惯了在xcode中直接通过项目模板生成项目的来说,这样的方式的确是有点不太方便。
但是在cocos2d-x v3.0 Beta版本中,采用了一种比较人性化图形界面创建方式。
在这里 点击打开链接 有详细的新版本使用介绍。
下面我实践一下如何创建一个 cocos2dx for ios & osx 的项目。(有两种方式)
1、第一种,当然是延续了2.2版本之后的直接命令行创建,这个具体方法可以请参考我之前的文章。点击打开链接
Example:
?
2、第二种,就是图形界面创建的方法 ①在终端中,进入引擎文件:cocos2d-x-3.0beta/tools/project-creator ②运行 ./create_project.py ③在如下图中进行图形界面方式创建项目:
注:
有了这个工具,妈妈再也不用担心我创建cocos2dx项目很麻烦了!想创建项目就直接点击几下就可以了。
二、运行引擎中附带的sample例子 进入 引擎文件: cocos2d-x-3.0beta/build 打开cocos2d_samples.xcodeproj 即可。 注:引擎中附带的例子文件比较大,所有打开和编译运行都需要一点时间,考验机子呀!
三、cocos2d-x-3.0beta 新特性介绍
注:下面先贴出所有新特性内容,下面的文章,将会根据新特性内容分析详述。
iOS 5.0 or newer
OS X 10.7 or newer
Windows 7 or newer
Windows Phone 8 or newer N/A for the moment
Linux Ubuntu 12.04 (or newer)
Browsers via Emscripten N/A for the moment
Marmalade N/A for the moment
BlackBerry N/A for the moment
gcc 4.7 for Linux or Android. For Android ndk-r9 or newer is required.
Visual Studio 2012 (for Windows)
Improved Labels
Improved renderer
New Event Dispatcher
Physics integration
New GUI
JavaScript
remote debugger
Remote Console support
Refactor Image - release memory in time and uniform the api of supported file format
Automatically generated Lua bindings, add LuaJavaBridge and LuaObjcBridge
Templated containers
A subset of C++11 features are being used in cocos2d-x:
strongly typed enums, for most of the cocos2d-x enums and constants
See ActionsTest.cpp for more examples
?
?
Constants and enums that started with
type errors. The new format is:
?
Examples:
?
The old values can still be used, but are not deprecated.
?
Since cocos2d-x already uses the
Examples:
?
v2.1 class names are still available, but they were tagged as deprecated.
Changes in free functions
For the drawing primitives:
They were added in the
The
For the gl proxy functions:
They were added in the
The
was removed
Examples:
?
v2.1 free functions are still available, but they were tagged as deprecated.
Example:
?
All singletons use
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:
Example:
?
The renderer functionality has been decoupled from the Scene graph / Node logic. A new object called
Auto-batching and auto-culling support has been added.
Please, see this document for detail information about its internal funcitonality:https://docs.google.com/document/d/17zjC55vbP_PYTftTZEuvqXuMb9PbYNxRFu0EGTULPK8/edit
All events like touch event, keyboard event, acceleration event and custom event are dispatched by
removed.
For TouchOneByOne:
?
For TouchAllAtOnce
?
?
?
?
?
?
?
Physics integration have five concepts:
in
A
?
A
when update.
?
A
?
A
?
A
classes contain the contact information:
?
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
?
Only configurating the *.ini files in the tools/tolua folder,not to write a lot of *.pkg files
When we want to add register and unregister functions of Lua function for class, we need to change the declarative and defined files and then bind to Lua. In v3.0, we use the
the
?
then implement them in the .cpp file. In the Lua script ,we use it as follow:
?
In v3.0 version, we only need to add the
?
?
Add a lot of deprecate funtions、table and classes to support 2.x version as far as possible Note:
Point、Size、Rect、Color3b、Color4b、Color4F、AffineTransform、FontDefinition、Array、Dictionary、PointArray are not bound. The difference is as follow:
?
Global functions about these classes are changed as follow:
?
Through the funtions of the LuaBasicConversion file,they can be converted the Lua table when they are as a parameter in the bindings generator.
不得不说,cocos2d-x的版本更迭真是快,而最新的cocos2d-x v3.0 Beta版本中包含了许多新的特性和与之前2.x版本不同的内容,虽然说,目前3.0只是beta版本,但目前很多游戏已经采用这个3.0版本了,估计3.0的最终版本也会很快推出。
从创建项目开始了解一下这个最新的3.0版本的一些新特性吧!
一、创建项目(针对在mac os x中进行开发)
在前面我有一篇文章 点击打开链接 已经介绍过在 cocos2dx 2.2 版本中创建项目只能是在终端中进行,对于习惯了在xcode中直接通过项目模板生成项目的来说,这样的方式的确是有点不太方便。
但是在cocos2d-x v3.0 Beta版本中,采用了一种比较人性化图形界面创建方式。
在这里 点击打开链接 有详细的新版本使用介绍。
下面我实践一下如何创建一个 cocos2dx for ios & osx 的项目。(有两种方式)
1、第一种,当然是延续了2.2版本之后的直接命令行创建,这个具体方法可以请参考我之前的文章。点击打开链接
Example:
?
注:
有了这个工具,妈妈再也不用担心我创建cocos2dx项目很麻烦了!想创建项目就直接点击几下就可以了。
二、运行引擎中附带的sample例子 进入 引擎文件: cocos2d-x-3.0beta/build 打开cocos2d_samples.xcodeproj 即可。 注:引擎中附带的例子文件比较大,所有打开和编译运行都需要一点时间,考验机子呀!
三、cocos2d-x-3.0beta 新特性介绍
注:下面先贴出所有新特性内容,下面的文章,将会根据新特性内容分析详述。
cocos2d-x v3.0 Release Notes
Misc Information
Download: http://cdn.cocos2d-x.org/cocos2d-x-3.0beta.zip Full Changelog: https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.0beta/CHANGELOG API Reference: http://www.cocos2d-x.org/reference/native-cpp/V3.0beta/index.htmlRequirements
Runtime Requirements
Android 2.3 or neweriOS 5.0 or newer
OS X 10.7 or newer
Windows 7 or newer
Windows Phone 8 or newer N/A for the moment
Linux Ubuntu 12.04 (or newer)
Browsers via Emscripten N/A for the moment
Marmalade N/A for the moment
BlackBerry N/A for the moment
Compiler Requirements
Xcode 4.6 (for iOS or Mac)gcc 4.7 for Linux or Android. For Android ndk-r9 or newer is required.
Visual Studio 2012 (for Windows)
Highlights of v3.0
Replaced Objective-C patters with C++ (C++11) patterns and best practicesImproved Labels
Improved renderer
New Event Dispatcher
Physics integration
New GUI
JavaScript
remote debugger
Remote Console support
Refactor Image - release memory in time and uniform the api of supported file format
Automatically generated Lua bindings, add LuaJavaBridge and LuaObjcBridge
Templated containers
Features in detail
C++11 features
Feature added in v3.0-pre-alpha0A 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
std::function
CallFunccan be created with an
std::function
CallFuncNcan be created with an
std::function
CallFuncNDand
CallFuncOwere removed since it can be created with simulated with
CallFuncNand
CallFunc.
See ActionsTest.cpp for more examples
MenuItemsupports
std::functionas callbacks
CallFuncexample:
?
MenuItemexample:
?
strongly typed enums
Feature added in v3.0-pre-alpha0Constants and enums that started with
k, and that usually were defined as
intor as simple
enumwhere replaced with strongly typed enums (
enum class) to prevent collisions and
type errors. The new format is:
?
?
override
To catch possible errors while overriding methods, subclasses with override methods have theoverridecontext keyword. Example:
?
Removed Objective-C patterns
Feature added in v3.0-pre-alpha0No more 'CC' prefix for C++ classes and free functions
Changes in classesSince cocos2d-x already uses the
cocos2dnamespace, there is not need to add the prefix
CCto all its classes.
Examples:
?
Changes in free functions
For the drawing primitives:
They were added in the
DrawPrimitivesnamespace
The
ccprefix was removed
For the gl proxy functions:
They were added in the
GLnamespace
The
ccGLprefix
was removed
Examples:
?
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:
?
Singletons use getInstance() and destroyInstance()
All singletons use getInstance()and
destroyInstance()(if applicable) to get and destroy the instance.
Examples:
?
getters
Getters now use the getprefix.
Examples:
?
constin their declaration. Example:
?
POD types
Methods that were receiving POD types as arguments (eg: TexParams,
Point,
Size, etc.) are being passed as
constreference.
Example:
?
New Renderer
Feature added in v3.0-betaThe renderer functionality has been decoupled from the Scene graph / Node logic. A new object called
Rendereris responsible for rendering the object.
Auto-batching and auto-culling support has been added.
Please, see this document for detail information about its internal funcitonality:https://docs.google.com/document/d/17zjC55vbP_PYTftTZEuvqXuMb9PbYNxRFu0EGTULPK8/edit
Improved LabelTTF / LabelBMFont
Feature added in v3.0-alpha0New EventDispatcher
Feature added in v3.0-alpha0All events like touch event, keyboard event, acceleration event and custom event are dispatched by
EventDispatcher.
TouchDispatcher,
KeypadDispatcher,
KeyboardDispatcher,
AccelerometerDispatcherwere
removed.
Adding Touch Event Listener
For TouchOneByOne:?
?
Adding Mouse Event Listener
?
Adding A Keyboard Event Listener
?
Adding An Acceleration Event Listener
?
Adding A Custom Event Listener
?
Dispatching A Custom Event
?
Setting Fixed Priority For A Listener
?
Removing Event Listener
Removing A Specified Event Listener
?Removing Custom Event Listener
?Removing All Listeners For An Event Listener Type
?Removing All Listeners
?Physics Integration
Feature added in v3.0-pre-alpha0Physics integration have five concepts:
PhysicsWorld,
PhysicsBody,
PhysicsShape,
PhysicsJointand
PhysicsContact. You must define
CC_USE_PHYSICSmacro
in
ccConfig.hto use the physics API.
PhysicsWorld
A PhysicsWorldobject simulates collisions and other physical properties, you do not create it directly, you can get it from scene which create with physics.
?
PhysicsBody
A PhysicsBodyobject is used to add physics simulation to a node. If you create a
PhysicsBodyand set it to a node, and add the node the a scene which create with physics, it will perform the physics simulation
when update.
?
PhysicsShape
A PhysicsShapeobject is a shape that make the body can have collisions. you can add one or more
PhysicsShapeto a
PhysicsBody. Shape classes:
PhysicsShapeCircle,
PhysicsShapeBox,
PhysicsShapePolygon,
PhysicsShapeEdgeSegment,
PhysicsShapeEdgeBox,
PhysicsShapeEdgePolygon,
PhysicsShapeEdgeChain.
?
PhysicsJoint
A PhysicsJointobject connects two physics bodies together so that they are simulated together by the physics world. Joint classes:
PhysicsJointFixed,
PhysicsJointLimit,
PhysicsJointPin,
PhysicsJointDistance,
PhysicsJointSpring,
PhysicsJointGroove,
PhysicsJointRotarySpring,
PhysicsJointRotaryLimit,
PhysicsJointRatchet,
PhysicsJointGear,
PhysicsJointMotor.
?
PhysicsContact
A PhysicsContactobject is created automatically to describes a contact between two physical bodies in a
PhysicsWorld. you can control the contact behavior from the physics contact event listener. Other
classes contain the contact information:
PhysicsContactPreSolve,
PhysicsContactPostSolve. The event listener for physics:
EventListenerPhysicsContact,
EventListenerPhysicsContactWithBodies,
EventListenerPhysicsContactWithShapes,
EventListenerPhysicsContactWithGroup.
?
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.?
?
deprecated functions and global variables
?Changes in the Lua bindings
Use bindings-generator tool for Lua binding
Only configurating the *.ini files in the tools/tolua folder,not to write a lot of *.pkg files
Use ScriptHandlerMgr to manage the register and unregister of Lua function
When we want to add register and unregister functions of Lua function for class, we need to change the declarative and defined files and then bind to Lua. In v3.0, we use the ScriptHandlerMgr. As an example, lets see
the
MenuItemclass: In the 2.x version, we needed to add a declaration in the MenuItem header file:
?
?
HandlerTypeenum in the
ScriptHandlerMgr, and the implementation in luascript as follow:
?
Use "cc" and "ccs" as module name
?
Deprecated funtions, tables and classes
Add a lot of deprecate funtions、table and classes to support 2.x version as far as possible Note:Rect does not support the origin and size member variables
Use the Lua table instead of the some structs and classes binding
Point、Size、Rect、Color3b、Color4b、Color4F、AffineTransform、FontDefinition、Array、Dictionary、PointArray are not bound. The difference is as follow:?
?
Known issues
You can find all the known issues "here":http://www.cocos2d-x.org/projects/native/issues相关文章推荐
- Cocos2d-x 3.0 新特性体验(1)创建项目+运行sample+新特性内容
- cocos2d-x 3.x中各种平台的创建项目命令,运行项目命令、运行testcpp命令
- [Cocos2d-x v3.x]Mac OX 创建新的Cocos2d-x 3.0 项目
- cocos2d-x 3.0 HelloWorld项目创建
- Cocos2d-x 3.0 新特性体验- 回调函数的变化
- 【iOS-cocos2d-X 游戏开发之四】Cocos2dX创建Android NDK新项目并编译导入Eclipse中正常运行!
- cocos2d-x 3.0 beta 创建新的项目
- Cocos2d-x 3.0开发小记(一)(创建项目)
- Cocos2d-x 3.0开发(二)使用自动脚本创建cocos2d-x 3.0项目
- cocos2d-x 3.0 创建项目
- Cocos2d-X 3.0 游戏软件环境搭建与项目创建
- cocos2d-x 3.x中各种平台的创建项目命令,运行项目命令、运行testcpp命令
- cocos命令行创建/编译/运行cocos2d-js项目
- cocos2d-x 3.0游戏开发xcode5环境的搭建以及项目创建
- cocos2d-x 3.0创建新项目
- 【iOS-cocos2d-X 游戏开发之四】Cocos2dX创建Android NDK新项目并编译导入Eclipse中正常运行! 推荐
- cocos2d-x 3.0 安装及创建项目
- Cocos2d-x 3.0 创建一个场景,并设置现场的时候,项目开始执行上主动
- cocos2d-x 3.x中各种平台的创建项目命令,运行项目命令、运行testcpp命令
- 【amazing cocos2d-x 3.0之二十二】cocos2d-x 3.0正式版创建项目