As promised, Cocos2d-x v3.8 have greatly improved the stability and API friendliness. On one side, we continue to improve 3D capacity by providing 3D physics collider, skybox background brush and key frame event callback in Animate3D. On another side, we have refined several core modules, including UI system, AudioEngine, FileUtils, Bindings Generator, etc.
Here is some highlighted improvments and API changes:
1. 3D Module
- Added 3D physics collider
- Supported setting camera background brushes with color/depth/skybox
- Added key frame event Callback in Animate3D
- Added light map support in Terrain
2. UI System
- Reimplemented and enhanced EditBox on Android
- Added ScrollViewBar for displaying a scroll bar at the side of ScrollView (JSB/Lua ready)
- Added RadioButton widget (JSB/Lua ready)
- Added HANYI FullType font support
3. AudioEngine
- AudioEngine supported audio preloading
- Bound new AudioEngine in JSB
4. FileUtils
- Added a set of file writing APIs: writeStringToFile, writeDataToFile, writeValueMapToFile, writeValueVectorToFile
5. Others
- Improved Bindings Generator tool
- Merged JSB test project into cocos2d test project
- framework: Support generate prebuilt libs of engine with debug mode
- console: Supported new portrait projects from templates
3D physics collider is a new type of physics object. It can be used as both trigger and collider.
Trigger is a region defined by physics shapes and can get callback when other physics objects enter or leave. Its usage is described in the following code:
Collider is similar to rigid body, it can give force to the rigid body that collides with it. However, it is static and has better performance than rigid body. It is proper to represent a static scene or objects using collider and dynamic part using rigid body. You can set colliderDes.isTrigger to false when you want to make it collider.
2. Camera background brushes
Different with previous versions, in v3.8, developers can choose to erase the camera’s background with 4 types of brush: none, color, depth, skybox. None brush means do nothing; Color brush erases background using given color and depth; depth brush erases background using given depth; skybox brush erases background using given skybox with 6 texture faces. The default brush is depth brush. The usage of brushes is showing below:
Similar to 2d AnimationFrame callback, frame event callback is supported in Animated3D now. It allows developer to set a callback to be invoked when specific frame is played. Sample code:
```cpp
auto animation = Animation3D::create(“XX.c3b”);
auto animate = Animate3D::create(animation);
ValueMap valuemap0;//you can add some user data here, it can be used in the frame event callback
//add a callback when frame 275 is played
animate->setKeyFrameUserInfo(275, valuemap0);
auto listener = EventListenerCustom::create(Animate3DDisplayedNotification, [&](EventCustom* event)
{
auto info = (Animate3D::Animate3DDisplayedEventInfo*)event->getUserData();
Terrain with light map is supported in v3.8, which means you can add a light map texture baked from other tools to the terrain. The light map texture contains light info, so that the terrain seems to be lighted with several lights. Terrain with light map can be created like this,
In the previous versions, the ScrollView doesn't have any visual notification for the current location in view. In v3.8, we have added a scroll bar attached to the ScrollView. You could tweak the the opacity, color, width and the duration for auto hiding the scroll bar. Speical thanks to @neokim.
There is only one RadioButton in checked state at the same time within a RadioButtonGroup. Special thanks to @neokim who have contributed the implementation of this new widget.
AudioEngine now supports preload audio files before playing it. For some large audio file, this feature can smooth the audio playing experience in user's games. Sample code:
In JSB, the default audio engine was SimpleAudioEngine (renamed to cc.audioEngine). It was the old audio engine provided since v2, and it have some inconvenience like delay time, no event support, etc. So we decided to provide new AudioEngine in JSB, the API remains the same as C++ API, and its usage can be found in [its test case](https://github.com/cocos2d/cocos2d-x/blob/v3/tests/js-tests/src/NativeTest/AudioEngineTest.js).
### FileUtils
1. New file writing APIs
In v3.8, we have provided a bunch of file writing APIs in FileUtils. Now you can use very simple APIs to write string, binary data, value map, and value vector into a file in user's file system. Each API is demonstrated in the following sample code:
Besides, you can retrieve the extension (in lower case) of a file with `FileUtils::getFileExtension` API.
### Others
1. Bindings Generator
In v3.8, we also improved our bindings generator tool, now it's even more powerful and be able to bind almost all kind of C++ APIs to script. Here is a detailed list about improvement in bindings generator.
- Supported generating auto bindings code for public member variables
- Avoid memory leak of non-Ref classes instance by controlling C++ object memory with JS object
- Made JSB classes automatically extendable if configured in classes_need_extend list
- Improved support for Lambda functions in JS auto bindings
2. JSB test project
In v3.8, JSB test project have been merged into C++ test project. That means cocos2d_js_tests.xcodeproj, cocos2d-js-win32.sln, cocos2d-js-win8.1-universal.sln have been removed. You can find jsb test targets in cocos2d_test.xcodeproj, cocos2d-win32.sln and cocos2d-win8.1-universal.sln.
3. Compile custom framework in debug mode
From v3.7, you was able to generate customized Cocos Framework from cocos2d-x. We have improved this ability in v3.8, now you will be able to generate framework in debug mode. Here is the some documentation about it:
- [How to customize Cocos Framework](http://www.cocos2d-x.org/docs/manual/studio/v4/chapter3/HowToCode/CustomizeFramework-v3.8/en)
- [How to generate Cocos Simulator](http://www.cocos2d-x.org/wiki/Cocos_gen-simulator)
4. Portrait projects support
From v3.8, you can generate portrait oriented games with Cocos Console:
```
cocos new -l cpp|lua|js --portrait MyPortraitGame
```
More details can be found in [Cocos new command](http://www.cocos2d-x.org/wiki/Cocos_new) and [Cocos Console general documentation](http://www.cocos2d-x.org/wiki/Cocos2d-console)
## Other changes
- [NEW] UI: Enhanced ScrollView with easing out scrolling
- [NEW] UI: Added PageView vertical scroll support
- [NEW] UI: Added PageView::JumpToPage API
- [NEW] UI: Added a setter for line width in DrawNode
- [NEW] Action: Permitted setting bitwise flags to action
- [NEW] Animate: Added Animate's getCurrentFrameIndex function
- [NEW] FileUtils: Added FileUtils::getFileExtension for getting file's extension name
- [NEW] Device: Added vibrate support to enable vibration for a duration
- [NEW] UserDefault: Supported removing key pairs from UserDefault
- [NEW] spine: Supported Spine runtime 2.3 (Both native and web engine)
- [NEW] console: Moved the framework-compile tools into cocos2d-console