Skip to content

Commit

Permalink
[Cocos2d-JS]Update 3.0a2 upgrade guide
Browse files Browse the repository at this point in the history
  • Loading branch information
pandamicro committed Apr 14, 2014
1 parent 041463d commit f1feb2a
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1,135 deletions.
87 changes: 66 additions & 21 deletions manual/framework/html5/release-notes/v3.0a/upgrade-guide/en.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Cocos2d-html5 upgrade guide from v2.2.2 to v3.0a2
#Cocos2d-html5 upgrade guide from v2.2.x to v3.0a2


##1. Event Manager
Expand Down Expand Up @@ -204,9 +204,54 @@ ccs.ObjectFactory.getInstance() --> ccs.objectFactory
[Detialed documentation](../../../v3.0/singleton-objs/en.md).
##7. GUI widgets
##7. **[New in alpha 2]** Object creation and class inheritance
* **7.1** GUI widgets of Cocostudio extension have been removed from Cocostudio and have been put into ccui package, so their prefix have also changed from `ccs.` to `ccui.`. The reason is that they are some useful widget components that can not only be used for Cocostudio but also for any other purpose. All classes and functions that have been refactored is listed below :
In Cocos2d-html5 2.2.x, to create an engine object like cc.Sprite, developers need to use the correct `create` functions, like this example :
```
var sprite = cc.Sprite.create(filename, rect);
var sprite = cc.Sprite.createWithTexture(texture, rect);
var sprite = cc.Sprite.createWithSpriteFrameName(spriteFrameName);
```
In Cocos2d-JS v3.0 alpha, we have made a great improvement, we merged all `createXXX` functions into one unified `create` function :
```
var sprite = cc.Sprite.create(filename, rect);
var sprite = cc.Sprite.create(texture, rect);
var sprite = cc.Sprite.create(spriteFrameName);
```
This changement affect not only cc.Sprite, but all similar classes, all classes and details about create function refactoration can be found in [this document](../../../v3.0/create-api/en.md).
As we never stop to improve our engine, in Cocos2d-JS v3.0 alpha2, we have made the `new` construction possible ! They share exactly the same parameters as `create` functions :
```
var sprite = new cc.Sprite(filename, rect);
var sprite = new cc.Sprite(texture, rect);
var sprite = new cc.Sprite(spriteFrameName);
```
In the meantime, for backward compatibility, we have kept all `create` functions also, so it's totally your choice. What's more important with this improvement is that the inheritance is much easier than before. Developers can now completely ignore all `initXXX` functions, you can simply override `ctor` function and call `this._super` with correct parameters, then your object will be correctly initialized:
```
var Enemy = cc.Sprite.extend({
hp: 0,
fileName: "enemy.png"
ctor: function (hp) {
this._super(fileName);
this.hp = hp;
}
});
var enemy1 = new Enemy(100);
```
As you can see, there isn't a single `init` function call, very convenient to use. All cocos2d (no extension) classes have been refactored to support this style, and JSB support it too. Document which discuss the `new` constructor and the inheritance will be pulished very soon.
##8. GUI widgets
* **8.1** GUI widgets of Cocostudio extension have been removed from Cocostudio and have been put into ccui package, so their prefix have also changed from `ccs.` to `ccui.`. The reason is that they are some useful widget components that can not only be used for Cocostudio but also for any other purpose. All classes and functions that have been refactored is listed below :
```
ccs.Layout --> ccui.Layout
Expand All @@ -229,9 +274,9 @@ ccs.ObjectFactory.getInstance() --> ccs.objectFactory
ccs.UILayer --> deleted
```
* **7.2** A new ui widget `ccui.RichText` has been added to v3.0a.
* **8.2** A new ui widget `ccui.RichText` has been added to v3.0a.
* **7.3** `ccs.UILayer` has been deleted from v3.0a, please add to node directly, for example:
* **8.3** `ccs.UILayer` has been deleted from v3.0a, please add to node directly, for example:
```
// usage in v2.2.2: A widget object need to through ccs.UILayer.addWidget to add to node object
Expand All @@ -246,7 +291,7 @@ ccs.ObjectFactory.getInstance() --> ccs.objectFactory
node .addChild(aWidget);
```
##8. NodeGrid
##9. NodeGrid
A new node `cc.NodeGrid` have been added to version 3.0a. This node should be used to host a target node and permit it to have the ability to run ActionGrid type action. In v2.2.2, cc.Node can directly play such actions, but this ability will be removed to keep cc.Node as simple as possible. So the comparaision between v2.2.2 and v3.0a is like the example below :
Expand All @@ -267,7 +312,7 @@ nodeGrid.runAction( shaky );
Note: In Cocos2d-html5 v3.0 version web, the old way still work fine, but if you want your game to be ported to native plateform with JSB, only the new way is supported.
##9. JSB related
##10. JSB related
We found that there are different needs for web app developers and JSB native app developers, and there are things that we can't perfectly merge, so here are those JSB only APIs, if you want to use them, please check the platform first.
Expand All @@ -277,7 +322,7 @@ if (cc.sys.isNative) {
}
```
* **9.1** C++ Macros
* **10.1** C++ Macros
In JSB project, there are some macros can only be modified in C++ level, whatever you do in JS can't modify them. These macros are listed below, they can be found in ccMacros.h and ccConfig.h:
Expand Down Expand Up @@ -305,7 +350,7 @@ if (cc.sys.isNative) {
CC_ENABLE_SCRIPT_BINDING
```
* **9.2** **[New in alpha 2]** cc.fileUtils
* **10.2** **[New in alpha 2]** cc.fileUtils
As cc.FileUtils have been replaced by cc.loader in Cocos2d-html5, but in JSB project, there are still some needs that can't be accomplished by cc.loader, so we decided to make cc.FileUtils a JSB only API. And to follow the singleton object API style, you don't need to call `cc.FileUtils.getInstance()`, `cc.fileUtils` is referring directly to the FileUtils singleton object. Detailed APIs are listed below:
Expand All @@ -327,7 +372,7 @@ if (cc.sys.isNative) {
All functions about search path configuration have been removed, because this will due to code inconsistence between Cocos2d-html5 and Cocos2d-JSB and eventually a high cost of maintainbility.
* **9.3** cc.AssetsManager
* **10.3** cc.AssetsManager
cc.AssetsManager is a class serves for managing and using remote resources on your server. It can also manage versions of resources and update them to most recent versions. Detailed APIs are listed below:
Expand All @@ -348,11 +393,11 @@ if (cc.sys.isNative) {
```
##10. Other API changements
##11. Other API changements
* **10.1** `cc.Broswser` and `sys` are replaced with `cc.sys`: [documentation](../../../v3.0/cc-sys/en.md).
* **11.1** `cc.Broswser` and `sys` are replaced with `cc.sys`: [documentation](../../../v3.0/cc-sys/en.md).
* **10.2** Some functions of `cc.AudioEngine` have been deleted :
* **11.2** Some functions of `cc.AudioEngine` have been deleted :
```
preloadMusic
Expand All @@ -361,7 +406,7 @@ if (cc.sys.isNative) {
preloadSound
```
* **10.3** cc.SAXParser
* **11.3** cc.SAXParser
These functions of `cc.SAXParser` have been deleted :
Expand All @@ -376,7 +421,7 @@ if (cc.sys.isNative) {
And `cc.PlistParser` is added to parse plist files: [cc.SAXParser documentation](../../../v3.0/cc-saxparser/en.md)
* **10.4** `addImageAsync` is merged into `addImage` of `cc.textureCache`.
* **11.4** `addImageAsync` is merged into `addImage` of `cc.textureCache`.
```
addImage(url) --> addImage(url)
Expand All @@ -385,14 +430,14 @@ if (cc.sys.isNative) {
**[New in alpha 2]** The new `addImage` have been synced in JSB.
* **10.5** Two of `MenuItemFont`'s functions have been refactored to fit the standard API sytle:
* **11.5** Two of `MenuItemFont`'s functions have been refactored to fit the standard API sytle:
```
fontName --> getFontName
fontSize --> getFontSize
```
* **9.6** cc.view
* **11.6** cc.view
Retina display have been supported for Apple devices, you can disable or enable it with `cc.view.enableRetina(enableOrNot)`, you can also detect whether retina display is currently on or not with `cc.view.isRetinaEnabled()`. At last, you can retrieve the retina display's pixel ratio by using `cc.view.getDevicePixelRat io()`, on Apple devices, it will return 2 when retina display is applied. By default, retina display is automatically activated for your game on Apply devices. If you want to change it, note that after you enable or disable retina display, you have to call `cc.view.setDesignResolutionSize(width, height, policy)` to make it applied to your game.
Expand All @@ -403,7 +448,7 @@ if (cc.sys.isNative) {
cc.view.isAutoFullScreenEnabled(); // this will return the current value
```
* **10.7** Global APIs deleted :
* **11.7** Global APIs deleted :
```
cc.IS_SHOW_DEBUG_ON_PAGE
Expand All @@ -429,7 +474,7 @@ if (cc.sys.isNative) {
ccs.UILayer
```
* **10.8** Global APIs added :
* **11.8** Global APIs added :
```
cc.warn
Expand All @@ -438,7 +483,7 @@ if (cc.sys.isNative) {
cc.BuilderReader.registerController
```
* **10.9** Global APIs refactored :
* **11.9** Global APIs refactored :
```
cc.Assert --> cc.assert
Expand Down Expand Up @@ -524,7 +569,7 @@ if (cc.sys.isNative) {
```
* **10.10** **[New in alpha 2]** Other changes in alpha 2
* **11.10** **[New in alpha 2]** Other changes in alpha 2
- cc.Node refactoration :
Expand Down
49 changes: 47 additions & 2 deletions manual/framework/html5/release-notes/v3.0a/upgrade-guide/zh.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Cocos2d-html5从v2.2.2到v3.0a2升级指南
#Cocos2d-html5从v2.2.x到v3.0a2升级指南


##1. 事件管理机制
Expand Down Expand Up @@ -199,7 +199,52 @@ ccs.TriggerMng.getInstance() --> ccs.triggerManager
ccs.ObjectFactory.getInstance() --> ccs.objectFactory
```
[详细文档](../../../v3.0/singleton-objs/zh.md).
[详细文档](../../../v3.0/singleton-objs/zh.md)。
##7. **[New in alpha 2]** 对象创建与类的继承
在Cocos2d-html5 2.2.x中,创建一个引擎对象比如cc.Sprite,开发者需要使用正确的`create`函数:
```
var sprite = cc.Sprite.create(filename, rect);
var sprite = cc.Sprite.createWithTexture(texture, rect);
var sprite = cc.Sprite.createWithSpriteFrameName(spriteFrameName);
```
在Cocos2d-JS v3.0 alpha中,我们做到一个非常重要的API进化,所有`createXXX`都被合并为统一的`create`函数:
```
var sprite = cc.Sprite.create(filename, rect);
var sprite = cc.Sprite.create(texture, rect);
var sprite = cc.Sprite.create(spriteFrameName);
```
这个改动不仅适用于cc.Sprite,同样适用于引擎中所有有类似API的类,支持的类列表以及关于`create`函数改造的更详细信息请参见[create API文档](../../../v3.0/create-api/en.md)。
我们从未停止改进我们的引擎,所以在Cocos2d-JS v3.0 alpha2中,引擎支持`new`直接构造对象!构造函数和`create`函数共享完全相同的参数:
```
var sprite = new cc.Sprite(filename, rect);
var sprite = new cc.Sprite(texture, rect);
var sprite = new cc.Sprite(spriteFrameName);
```
与此同时,为了向后兼容性,所有`create`函数也被保留,使用哪种API风格完全是开发者自由的选择。更重要的是,这个改进使得类的继承变得前所未有的简单。开发者现在可以完全忽略所有的`initXXX`函数,你可以简单得通过重载`ctor`函数并使用正确的参数调用`this._super`即可完成对象的初始化:
```
var Enemy = cc.Sprite.extend({
hp: 0,
fileName: "enemy.png"
ctor: function (hp) {
this._super(fileName);
this.hp = hp;
}
});
var enemy1 = new Enemy(100);
```
如上所示,一个`init`函数都不需要调用,非常便于使用。所有cocos2d(不包括extension)类都被重构以支持这种风格,而且JSB也同样完美支持。关于`new`对象构造和类的继承的详细文档将在近期推出。
##7. GUI控件
Expand Down
Loading

0 comments on commit f1feb2a

Please sign in to comment.