Cocos2dx 3.9更新说明
以下是3.9 beta0版本的亮点提要与API的变化:
3D模块:
功能 3D MotionStreak,支持拖尾效果。
优化 Sprite3D支持材质系统
2D模块:
功能 增加帧回调函数和动画回调函数
功能 新增脚本组件系统
功能 使用Component重构2D物理组件
功能 EditBox:优化iOS和Win32平台的实现,统一与Android平台的表现
优化 移除AssetsManager,AssetsManagerEx和Downloader对curl的依赖
优化 优化粒子性能
其他:
功能 JSB,Action支持继承,重写update函数
优化 Web引擎的ScrollView性能优化
优化 Web引擎九宫格精灵性能优化
优化 H5 分离并整理setTexture和updateColor的耦合
功能 支持Xcode 7和iOS 9真机调试发布
下载地址:
http://www.cocos2d-x.org/filedown/cocos2d-x-3.9beta0.zip
此包包含c++、js、lua
主要功能详述:
3DMotionStreak
支持3D拖拽效果。增加MotionStreak3D类。详细使用可以查看Sprite3Dtest测试示例。
Sprite3D
支持材质系统
新增Sprite3Dmaterial类,方便内置材质的创建。
增加帧回调函数和动画回调函数
ActionTimelineData类增加addFrameEndCallFunc, removeFrameEndCallclearFrameEndCalls接口,方便添加、移除特定帧事件。
脚本组件
脚本组件用来扩展C++节点,你可以给一个节点添加脚本组件,然后在脚本组件中可以接收onEnter, onExit和update事件。下面是Lua示例代码:
auto luaComponent =ComponentLua::create("player.lua");player->addComponent(luaComponent); ``````lua // player.lualocal player = { onEnter = function(self)-- do some things in onEnter endonExit =function(slef)-- do some things in onExitendupdate =function(self)-- do some things every frameend
--it is needed to return player to let c++ nodes know it return player ```
Javascript可以使用相同的方式,只需要使用ComponentJS替换ComponentLua。
在lua组件和javascript组件间有一些区别:
l 在lua脚本中,需要返回lua组件对象,在Javascript脚本中,只需要继承自cc.ComponentJS
l Lua组件只能在Lua项目中使用, Javascript组件只能在Javascript项目中使用。
更多的详细信息请查看ests/lua-tests/src/ComponentTest和tests/js-tests/src/ComponentTest示例项目。
2D
物理组件
在3.9版本之前,在Node类身上有很多物理系统相关的函数,比如Node:setPhysicsBody()。在3.9版本中,这些代码都被统一移动到物理组件中。
使用物理组件后,使用物理系统的方式发生了改变。在3.9版本之前,如下使用物理系统。
auto node = Node::create();node->setPhysicsBody(PhysicsBody::createEdgeBox(...));
在3.9版本中,使用下面的方式:
auto node = Node::create(); node->addComponent(PhysicsBody::createEdgeBox(...));
EditBox
优化,iOS
和Win32
平台
1.弹出框的输入长度限制
2.弹出框支持密文输入
3.弹出框不阻塞游戏进程
4.实时同步弹出框的输入内容
移除AssetsManager,AssetsManagerEx
和Downloader
对curl
的依赖
从v3.9开始,iOS版本和Android版本将不再依赖libcurl,这使得游戏的发布包进一步减小,并且也解决了一些由libcurl引入的bug,尤其是对于热更新功能,现在通过使用iOS和Android系统库,进一步提升了其稳定性
JSB Action
支持继承,重写update
函数
在旧版本的JSB中,开发者不可以在JS脚本中继承Action /ActionInterval / ActionInstant等Action类,因为其update函数的重写不会被调用,在v3.9中,这个问题已经被解决了,开发者可以自由得写出Action的子类,并扩展其功能。关于如何编写可以参考ActionTest / ActionCustomTest测试例中的用法
Web
引擎的ScrollView
性能优化
Web引擎中,ScrollView, ListView是大量被使用的UI控件,但在之前的版本,他们的性能不够优秀,尤其是当其子控件非常多的时候。在v3.9中,我们优化了它的渲染性能,只会绘制当前屏幕上可见的内容,不可见内容已经全部被剔除。测试数据显示,这在不同设备和浏览器上,v3.9的渲染效率是v3.8的两倍到四倍。
Web
引擎九宫格精灵性能优化
将以往使用节点拼接方式构建九宫格精灵改为了使用九个渲染指令,降低了内存使用,提升渲染性能
Web引擎解除Sprite的setTexture和updateColor的耦合
1. 将Sprite里面的部分渲染逻辑清理出来,updateColor由纹理自己完成,而不需要逻辑节点Sprite去执行具体的绘制工作。
2. 修复旧的4色图更改颜色全黑状态下和新版本的颜色更新差异问题。
3. 优化纹理更新逻辑:
原纹理更新逻辑是:setTexture的时候存入_texture,当用户改变颜色的时候,将现有纹理存入_originalTexture,并且将新的纹理放入_texture。频繁的替换纹理,非常容易造成纹理错误等。新的纹理机制是:setTexture的时候存入_texture,并且生成_renderTexture变量指向_texture,当颜色更新等操作的时候,只需要修改_renderTexture(分离了用户操作纹理和引擎内部操作纹理的耦合),不需要一直替换_texture。
4. 稍微优化了SpriteCanvas内部rendering的if else等逻辑
5. 合并了部分引擎内的重复UpdateColor代码
支持Xcode 7
和iOS 9
真机调试发布
在v3.8.1版本中,Cocos工程已经可以在Xcode 7上编译并在模拟器中调试,然而对于iOS 9真机调试还遗留一个小bug,在v3.9中,已经彻底解决了iOS 9真机调试的问题。
其他变化
Label: Added line spacing/leadingfeature to Label.
ListView: Added APIs to scroll tospecific item in list.
ListView: Added APIs to get an itemin specific position like center, leftmost, rightmost, topmost and bottommost.
ListView: Added a feature formagnetic scrolling.
Animate: AddedActionTimeline::setAnimationEndCallBack and ActionTimeline::addFrameEndCallFunc.
Animate: AddedCSLoader::createNodeWithVisibleSize, CSLoader::createNodeWithVisibleSize andmoved "ui::Helper::DoLayout" into them.
Stuio: Added support for CocosStudio Light3D.
Platform: Added the missing CURLsupport to the Windows 10 UWP version.
Platform: Added UIEditBox support onlinux platform.
3D: Added non-null checks inPUScriptCompiler::visit before dereferencing.
3D: Refined SkyboxBrush by making theshader parameter take effect at once.
Label: Changed label font size type tofloat to support high precision when font size is small.
ListView: Fixed an issue that listview's Magnetic::CENTER is not working well when non-bounceable.
ListView: Added feature of jumping to aspecific item in list view.
Sprite: Added "a unsupport imageformat!" log when creating a sprite in CCImage.cpp.
ScrollView: Merge logics of Scroll Viewfor scroll by inertia and auto scroll into one.
Animate: Moved initialization of imageto an appropriate location, because it always called twice inSpriteFrameCache::addSpriteFramesWithFile().
Simulator: Changed the size ofstartFlag to 13.
Simulator: Show Node and Skeleton inthe middle of the simulator.
Simulator: Removed screen directioncheck in simulator to avoid render error.
Pysics: Refined components to improve physicsperformance.
UI: Refined ComponentContainer toimprove performance.
UI: EventListenerMouse will dispatchEventMouse events.
OpenGL: Added check forglfwCreateWindow.
Platform: Fixed a crash on xiaomi2 ifCocos2d-x is built as a dynamic library.
Platform: Updated libcococs2d name tov3.9 on WinRT platforms.
Platform: Added some support for mouseon WinRT. Include: Show/Hide mouse cursor; Mouse event implemented similarDesktop version; Left button send mouse event and touch;Support other mousebutton and scroll wheel.
Platform: Correct the convertionbetween unicode and utf8 on WinRT.
Platform: Improved EditBox implement onWin32 platform.
JS: Addjsb.fileUtils.writeDataToFile().
JS: Set js templates Mac targetplatform from null to 10.7.
JS: Removed the static define ofvariable in headfile of ScriptingCore.
Lua: Added AssetsManagerEx constantsUPDATE_FAILED and ERROR_DECOMPRESS in Lua.
Lua / JS: Refined lua/js binding tool.
I/O: Refined AssetsManagerEx unzippingby using async.
Web: Improved logic of jsb_boot.js to syncwith the web engine behavior.
Web: Sync with CCBoot for web.
Build: Fixed various compiler warningson Xcode 7.
Build: Fixed Wformat-security warningon Xcode.
Build: Fixed a compile error in__LayerRGBA.
Tool: Added tools for generatingdocuments automatically.
Doc: Clean up the code of setRect()function.
Doc: Fixed a minor typo and renamedINTIAL_CAPS_ALL_CHARACTERS to INITIAL_CAPS_ALL_CHARACTERS in UIEditBox.
你也可以在https://github.com/cocos2d/cocos2d-x/blob/v3/CHANGELOG这里查看全部变化.
NEW APIS
脚本组件模块
添加ComponentLua和ComponentJS组件类,方便添加Lua,JS脚本。
3D MotionStreak
增加MotionStreak3D类,查看https://github.com/cocos2d/cocos2d-x/pull/13647/files, 提供3D拖尾效果支持。
JSB模块
增加cc.fileUtils.writeDataToFile,查看https://github.com/cocos2d/cocos2d-x/pull/13726https://github.com/cocos2d/cocos2d-x/pull/13726
Spritedebug draw功能
ccConfig.h中的增加#defineCC_SPRITE_DEBUG_DRAW,设置为1开启Debug框绘制
Sprite3D支持材质系统
新增Sprite3Dmaterial类,方便内置材质的创建。
ActionTimelineData新增接口
ActionTimeline::removeFrameEndCallFunc addFrameEndCallFunc,removeFrameEndCall clearFrameEndCalls
ListView新增接口:
1 支持直接滚动到特定的列表项。
2 支持获取特定位置的项,如中心,最左,最右,最上,最下。
3 添加滚动吸附功能。
详细查看https://github.com/cocos2d/cocos2d-x/pull/13723
CCNode,补充遗漏的接口
getChildByTag
Label新增接口
setLineSpacing,getLineSpacing
CSLoader新增接口
createNodeWithVisibleSize,createNodeWithVisibleSize
CCComponentContainer
移除isEmpty()接口.
CCSprite类
移除原来的debugDraw(bool on);
凑凑热闹