From 3d535aec20ee5320897de29c5862aea86c8d4ec3 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 20 Apr 2016 10:32:34 +0800 Subject: [PATCH 1/2] Perfection API --- CCDebugger.js | 85 +++++++++++++---- cocos2d/core/CCActionManager.js | 94 ++++++++++++++----- cocos2d/core/CCDirector.js | 4 + cocos2d/core/components/CCCanvas.js | 14 +-- .../components/CCComponentEventHandler.js | 9 +- cocos2d/core/load-pipeline/asset-table.js | 10 +- cocos2d/core/platform/callbacks-invoker.js | 4 +- cocos2d/core/value-types/CCTypes.js | 37 +++++--- extensions/ccpool/CCPool.js | 26 +++-- predefine.js | 5 +- 10 files changed, 211 insertions(+), 77 deletions(-) diff --git a/CCDebugger.js b/CCDebugger.js index 000a28e4ef..c78aef1f52 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -326,36 +326,65 @@ function _formatString (arg) { var Enum = require('./cocos2d/core/value-types/CCEnum'); /** - * Enum for debug modes. + * !#en Enum for debug modes. + * !#zh 调试模式 * @enum DebugMode */ cc.DebugMode = Enum({ /** - * @property {number} NONE - The debug mode none. + * !#en The debug mode none. + * !#zh 禁止模式,禁止显示任何日志信息。 + * @property NONE. + * @type {Number} + * @static */ NONE: 0, /** - * @property {number} INFO - The debug mode info. + * !#en The debug mode info. + * !#zh 信息模式,在 console 中显示所有日志。 + * @property INFO + * @type {Number} + * @static */ INFO: 1, /** - * @property {number} WARN - The debug mode warn. + * !#en The debug mode warn. + * !#zh 警告模式,在 console 中只显示 warn 级别以上的(包含 error)日志。 + * @property WARN + * @type {Number} + * @static */ WARN: 2, /** - * @property {number} ERROR - The debug mode error. + * !#en The debug mode error. + * !#zh 错误模式,在 console 中只显示 error 日志。 + * @property ERROR + * @type {Number} + * @static */ ERROR: 3, /** - * @property {number} INFO_FOR_WEB_PAGE - The debug mode info for web page. + * !#en The debug mode info for web page. + * !#zh 信息模式(仅 WEB 端有效),在画面上输出所有信息。 + * @property INFO_FOR_WEB_PAGE + * @type {Number} + * @static */ INFO_FOR_WEB_PAGE: 4, /** - * @property {number} WARN_FOR_WEB_PAGE - The debug mode warn for web page. + * !#en The debug mode warn for web page. + * !#zh 警告模式(仅 WEB 端有效),在画面上输出 warn 级别以上的(包含 error)信息。 + * @property WARN_FOR_WEB_PAGE + * @type {Number} + * @static */ WARN_FOR_WEB_PAGE: 5, /** - * @property {number} ERROR_FOR_WEB_PAGE - The debug mode error for web page. + * !#en The debug mode error for web page. + * !#zh 错误模式(仅 WEB 端有效),在画面上输出 error 信息。 + * @property ERROR_FOR_WEB_PAGE + * @type {Number} + * @static */ ERROR_FOR_WEB_PAGE: 6 }); @@ -367,7 +396,8 @@ cc.DebugMode = Enum({ var jsbLog = cc.log || console.log; /** - * Init Debug setting. + * !#en Init Debug setting. + * !#zh 设置调试模式。 * @method _initDebugSetting * @param {DebugMode} mode */ @@ -412,12 +442,18 @@ cc._initDebugSetting = function (mode) { if (!console.warn) console.warn = console.log; /** - * Outputs an error message to the Cocos Creator Console (editor) or Web Console (runtime). - * - In Cocos Creator, error is red. - * - In Chrome, error have a red icon along with red message text. + * !#en + * Outputs an error message to the Cocos Creator Console (editor) or Web Console (runtime).
+ * - In Cocos Creator, error is red.
+ * - In Chrome, error have a red icon along with red message text.
+ * !#zh + * 输出错误消息到 Cocos Creator 编辑器的 Console 或运行时页面端的 Console 中。
+ * - 在 Cocos Creator 中,错误信息显示是红色的。
+ * - 在 Chrome 中,错误信息有红色的图标以及红色的消息文本。
+ * * @method error - * @param {any} obj - A JavaScript string containing zero or more substitution strings. - * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. + * @param {Any} obj - A JavaScript string containing zero or more substitution strings. + * @param {Any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. */ if (CC_EDITOR) { cc.error = Editor.error; @@ -440,12 +476,17 @@ cc._initDebugSetting = function (mode) { }; if (mode !== cc.DebugMode.ERROR) { /** + * !#en * Outputs a warning message to the Cocos Creator Console (editor) or Web Console (runtime). * - In Cocos Creator, warning is yellow. * - In Chrome, warning have a yellow warning icon with the message text. + * !#zh + * 输出警告消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。
+ * - 在 Cocos Creator 中,警告信息显示是黄色的。
+ * - 在 Chrome 中,警告信息有着黄色的图标以及黄色的消息文本。
* @method warn - * @param {any} obj - A JavaScript string containing zero or more substitution strings. - * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. + * @param {Any} obj - A JavaScript string containing zero or more substitution strings. + * @param {Any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. */ if (CC_EDITOR) { cc.warn = Editor.warn; @@ -466,10 +507,11 @@ cc._initDebugSetting = function (mode) { } else if (mode === cc.DebugMode.INFO) { /** - * Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime). + * !#en Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime). + * !#zh 输出一条消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。 * @method log - * @param {any} obj - A JavaScript string containing zero or more substitution strings. - * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. + * @param {Any} obj - A JavaScript string containing zero or more substitution strings. + * @param {Any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. */ if (CC_JSB) { cc.log = jsbLog; @@ -484,9 +526,14 @@ cc._initDebugSetting = function (mode) { }; } /** + * !#en * Outputs an informational message to the Cocos Creator Console (editor) or Web Console (runtime). * - In Cocos Creator, info is blue. * - In Firefox and Chrome, a small "i" icon is displayed next to these items in the Web Console's log. + * !#zh + * 输出一条信息消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。 + * - 在 Cocos Creator 中,Info 信息显示是蓝色的。
+ * - 在 Firefox 和 Chrome 中,Info 信息有着小 “i” 图标。 * @method info * @param {any} obj - A JavaScript string containing zero or more substitution strings. * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. diff --git a/cocos2d/core/CCActionManager.js b/cocos2d/core/CCActionManager.js index f1bf3dd7b2..c09cfc8063 100644 --- a/cocos2d/core/CCActionManager.js +++ b/cocos2d/core/CCActionManager.js @@ -55,6 +55,7 @@ var HashElement = cc._Class.extend(/** @lends cc.HashElement# */{ }); /** + * !#en * cc.ActionManager is a class that can manage actions.
* Normally you won't need to use this class directly. 99% of the cases you will use the CCNode interface, * which uses this class's singleton object. @@ -62,7 +63,13 @@ var HashElement = cc._Class.extend(/** @lends cc.HashElement# */{ * Examples:
* - When you want to run an action where the target is different from a CCNode.
* - When you want to pause / resume the actions
- * + * !#zh + * cc.ActionManager 是可以管理动作的单例类。
+ * 通常你并不需要直接使用这个类,99%的情况您将使用 CCNode 的接口。
+ * 但也有一些情况下,您可能需要使用这个类。
+ * 例如: + * - 当你想要运行一个动作,但目标不是 CCNode 类型时。
+ * - 当你想要暂停/恢复动作时。
* @class ActionManager * @example {@link utils/api/engine/docs/cocos2d/core/CCActionManager/ActionManager.js} */ @@ -87,10 +94,18 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ this._currentTargetSalvaged = false; }, - /** Adds an action with a target. + /** + * !#en + * Adds an action with a target.
* If the target is already present, then the action will be added to the existing target. * If the target is not present, a new instance of this target will be created either paused or not, and the action will be added to the newly created target. * When the target is paused, the queued actions won't be 'ticked'. + * !#zh + * 增加一个动作,同时还需要提供动作的目标对象,目标对象是否暂停作为参数。
+ * 如果目标已存在,动作将会被直接添加到现有的节点中。
+ * 如果目标不存在,将为这一目标创建一个新的实例,并将动作添加进去。
+ * 当目标状态的 paused 为 true,动作将不会被执行 + * * @method addAction * @param {Action} action * @param {Node} target @@ -120,7 +135,8 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ }, /** - * Removes all actions from all the targets. + * !#en Removes all actions from all the targets. + * !#zh 移除所有对象的所有动作。 * @method removeAllActions */ removeAllActions:function () { @@ -131,11 +147,16 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ this.removeAllActionsFromTarget(element.target, true); } }, - /** Removes all actions from a certain target.
+ /** + * !#en + * Removes all actions from a certain target.
* All the actions that belongs to the target will be removed. + * !#zh + * 移除指定对象上的所有动作。
+ * 属于该目标的所有的动作将被删除。 * @method removeAllActionsFromTarget - * @param {object} target - * @param {boolean} forceDelete + * @param {Object} target + * @param {Boolean} forceDelete */ removeAllActionsFromTarget:function (target, forceDelete) { // explicit null handling @@ -154,7 +175,9 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ } } }, - /** Removes an action given an action reference. + /** + * !#en Removes an action given an action reference. + * !#zh 移除指定的动作。 * @method removeAction * @param {Action} action */ @@ -177,10 +200,12 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ } }, - /** Removes an action given its tag and the target + /** + * !#en Removes an action given its tag and the target. + * !#zh 删除指定对象下特定标签的一个动作,将删除首个匹配到的动作。 * @method removeActionByTag * @param {Number} tag - * @param {object} target + * @param {Object} target */ removeActionByTag:function (tag, target) { if(tag === cc.Action.TAG_INVALID) @@ -202,10 +227,12 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ } }, - /** Gets an action given its tag an a target + /** + * !#en Gets an action given its tag an a target. + * !#zh 通过目标对象和标签获取一个动作。 * @method getActionByTag * @param {Number} tag - * @param {object} target + * @param {Object} target * @return {Action|Null} return the Action with the given tag on success */ getActionByTag:function (tag, target) { @@ -227,13 +254,22 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ }, - /** Returns the numbers of actions that are running in a certain target.
+ /** + * !#en + * Returns the numbers of actions that are running in a certain target.
* Composable actions are counted as 1 action.
* Example:
* - If you are running 1 Sequence of 7 actions, it will return 1.
* - If you are running 7 Sequences of 2 actions, it will return 7. + * !#zh + * 返回指定对象下所有正在运行的动作数量。
+ * 组合动作被算作一个动作。
+ * 例如:
+ * - 如果您正在运行 7 个动作组成的序列动作(Sequence),这个函数将返回 1。
+ * - 如果你正在运行 2 个序列动作(Sequence)和 5 个普通动作,这个函数将返回 7。
+ * * @method numberOfRunningActionsInTarget - * @param {object} target + * @param {Object} target * @return {Number} */ numberOfRunningActionsInTarget:function (target) { @@ -243,18 +279,22 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ return 0; }, - /** Pauses the target: all running actions and newly added actions will be paused. + /** + * !#en Pauses the target: all running actions and newly added actions will be paused. + * !#zh 暂停指定对象:所有正在运行的动作和新添加的动作都将会暂停。 * @method pauseTarget - * @param {object} target + * @param {Object} target */ pauseTarget:function (target) { var element = this._hashTargets[target.__instanceId]; if (element) element.paused = true; }, - /** Resumes the target. All queued actions will be resumed. + /** + * !#en Resumes the target. All queued actions will be resumed. + * !#zh 让指定目标恢复运行。在执行序列中所有被暂停的动作将重新恢复运行。 * @method resumeTarget - * @param {object} target + * @param {Object} target */ resumeTarget:function (target) { var element = this._hashTargets[target.__instanceId]; @@ -263,7 +303,8 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ }, /** - * Pauses all running actions, returning a list of targets whose actions were paused. + * !#en Pauses all running actions, returning a list of targets whose actions were paused. + * !#zh 暂停所有正在运行的动作,返回一个包含了那些动作被暂停了的目标对象的列表。 * @method pauseAllRunningActions * @return {Array} a list of targets whose actions were paused. */ @@ -281,7 +322,8 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ }, /** - * Resume a set of targets (convenience function to reverse a pauseAllRunningActions or pauseTargets call) + * !#en Resume a set of targets (convenience function to reverse a pauseAllRunningActions or pauseTargets call). + * !#zh 让一组指定对象恢复运行(用来逆转 pauseAllRunningActions 效果的便捷函数)。 * @method resumeTargets * @param {Array} targetsToResume */ @@ -296,7 +338,8 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ }, /** - * Pause a set of targets + * !#en Pause a set of targets. + * !#zh 暂停一组指定对象。 * @method pauseTargets * @param {Array} targetsToPause */ @@ -310,8 +353,13 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ } }, - /** purges the shared action manager. It releases the retained instance.
- * because it uses this, so it can not be static + /** + * !#en + * purges the shared action manager. It releases the retained instance.
+ * because it uses this, so it can not be static. + * !#zh + * 清除共用的动作管理器。它释放了持有的实例。
+ * 因为它使用 this,因此它不能是静态的。 * @method purgeSharedManager */ purgeSharedManager:function () { @@ -362,6 +410,8 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{ }, /** + * !#en The ActionManager update。 + * !#zh ActionManager 主循环。 * @method update * @param {Number} dt delta time in seconds */ diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index ef2a283ce2..3467848d57 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -32,6 +32,7 @@ cc.g_NumberOfDraws = 0; //---------------------------------------------------------------------------------------------------------------------- /** + * !#en *

* ATTENTION: USE cc.director INSTEAD OF cc.Director.
* cc.director is a singleton object which manage your game's logic flow.
@@ -63,6 +64,9 @@ cc.g_NumberOfDraws = 0; * - Scheduled timers & drawing are synchronizes with the refresh rate of the display
* - Only supports animation intervals of 1/60 1/30 & 1/15
*

+ * + * !#zh 导演类,负责创建和处理主窗口,以及管理场景执行。 + * * @class Director */ cc.Director = Class.extend(/** @lends cc.Director# */{ diff --git a/cocos2d/core/components/CCCanvas.js b/cocos2d/core/components/CCCanvas.js index c269b22e76..c65298cecf 100644 --- a/cocos2d/core/components/CCCanvas.js +++ b/cocos2d/core/components/CCCanvas.js @@ -61,7 +61,8 @@ var Canvas = cc.Class({ statics: { /** - * Current active canvas, the scene should only have one active canvas at the same time. + * !#en Current active canvas, the scene should only have one active canvas at the same time. + * !#zh 当前激活的画布组件,场景同一时间只能有一个激活的画布。 * @property {Canvas} instance * @static */ @@ -71,7 +72,8 @@ var Canvas = cc.Class({ properties: { /** - * The desigin resolution for current scene. + * !#en The desigin resolution for current scene. + * !#zh 当前场景设计分辨率。 * @property {cc.Size} designResolution * @default new cc.Size(960, 640) */ @@ -92,8 +94,8 @@ var Canvas = cc.Class({ _fitHeight: true, /** - * !#zh: 是否优先将设计分辨率高度撑满视图高度 - * + * !#en TODO + * !#zh: 是否优先将设计分辨率高度撑满视图高度。 * @property {Boolean} fitHeight * @default false */ @@ -111,8 +113,8 @@ var Canvas = cc.Class({ }, /** - * !#zh: 是否优先将设计分辨率宽度撑满视图宽度 - * + * !#en TODO + * !#zh: 是否优先将设计分辨率宽度撑满视图宽度。 * @property {Boolean} fitWidth * @default false */ diff --git a/cocos2d/core/components/CCComponentEventHandler.js b/cocos2d/core/components/CCComponentEventHandler.js index 5be9ea949c..74ed52d673 100644 --- a/cocos2d/core/components/CCComponentEventHandler.js +++ b/cocos2d/core/components/CCComponentEventHandler.js @@ -35,11 +35,10 @@ * @class Component.EventHandler * @example * // Create new EventHandler - * 1. var eventHandler = cc.Component.EventHandler(target, "MainMenu", "OnClick"); - * 2. var eventHandler = cc.Component.EventHandler(); - * eventHandler.target = newTarget; - * eventHandler.component = "MainMenu"; - * eventHandler.handler = "OnClick" + * var eventHandler = cc.Component.EventHandler(); + * eventHandler.target = newTarget; + * eventHandler.component = "MainMenu"; + * eventHandler.handler = "OnClick" */ cc.Component.EventHandler = cc.Class({ name: 'cc.ClickEvent', diff --git a/cocos2d/core/load-pipeline/asset-table.js b/cocos2d/core/load-pipeline/asset-table.js index 499663d93d..1c91c901c4 100644 --- a/cocos2d/core/load-pipeline/asset-table.js +++ b/cocos2d/core/load-pipeline/asset-table.js @@ -39,8 +39,9 @@ function normalizePath (path) { var GLOB = '**/*'; -/** - * AssetTable is used to find asset's uuid by url +/* + * !#en AssetTable is used to find asset's uuid by url. + * !#zh AssetTable 用于查找资源的 uuid 和 url。 * @class AssetTable * @constructor */ @@ -91,7 +92,8 @@ cc.js.mixin(AssetTable.prototype, { }, /** - * Returns all asset paths in the table. + * !#en Returns all asset paths in the table. + * !#zh 返回表中的所有资源路径。 * @method getAllPaths * @return {string[]} */ @@ -175,6 +177,8 @@ cc.js.mixin(AssetTable.prototype, { //}, /** + * !#en TODO + * !#zh 以路径为 key,uuid 为值添加到表中。 * @method add * @param {string} path - the path to load, should NOT include filename extensions. * @param {string} uuid diff --git a/cocos2d/core/platform/callbacks-invoker.js b/cocos2d/core/platform/callbacks-invoker.js index 949430bfd6..42f042355d 100644 --- a/cocos2d/core/platform/callbacks-invoker.js +++ b/cocos2d/core/platform/callbacks-invoker.js @@ -176,8 +176,8 @@ CallbacksHandler.prototype.remove = function (key, callback, target) { /** - * The callbacks invoker to handle and invoke callbacks by key - * + * !#en The callbacks invoker to handle and invoke callbacks by key. + * !#zh CallbacksInvoker 用来根据 Key 管理并调用回调方法。 * @class CallbacksInvoker * @constructor * @extends _CallbacksHandler diff --git a/cocos2d/core/value-types/CCTypes.js b/cocos2d/core/value-types/CCTypes.js index e83efafa63..f2ca452f94 100644 --- a/cocos2d/core/value-types/CCTypes.js +++ b/cocos2d/core/value-types/CCTypes.js @@ -170,25 +170,40 @@ cc.js.get(cc.BlendFunc, "ADDITIVE", cc.BlendFunc._additive); */ cc.blendFuncDisable = cc.BlendFunc._disable; -/** - * Common usage: +/* + * !#en + * Common usage:
* - * var fontDef = new cc.FontDefinition(); - * fontDef.fontName = "Arial"; - * fontDef.fontSize = 12; - * ... + * var fontDef = new cc.FontDefinition();
+ * fontDef.fontName = "Arial";
+ * fontDef.fontSize = 12;
+ * ...
* - * OR using inline definition usefull for constructor injection + * OR using inline definition usefull for constructor injection
* - * var fontDef = new cc.FontDefinition({ - * fontName: "Arial", - * fontSize: 12 + * var fontDef = new cc.FontDefinition({
+ * fontName: "Arial",
+ * fontSize: 12
+ * });
+ * + * !#zh + * 常见用法:
+ * var fontDef = new cc.FontDefinition();
+ * fontDef.fontName = "Arial";
+ * fontDef.fontSize = 12;
+ * ...
+ * + * 或使用定义构造函数:
+ * + * var fontDef = new cc.FontDefinition({
+ * fontName: "Arial",
+ * fontSize: 12
* }); * * @class FontDefinition * @constructor */ -/** +/* * !#en TODO * !#zh 定义字体基本属性的结构体。 * @method FontDefinition diff --git a/extensions/ccpool/CCPool.js b/extensions/ccpool/CCPool.js index 4941c07a8f..f4f88af400 100644 --- a/extensions/ccpool/CCPool.js +++ b/extensions/ccpool/CCPool.js @@ -25,15 +25,20 @@ ****************************************************************************/ /** - *

+ * !#en * cc.pool is a singleton object serves as an object cache pool.
* It can helps you to improve your game performance for objects which need frequent release and recreate operations
* Some common use case is :
* 1. Bullets in game (die very soon, massive creation and recreation, no side effect on other objects)
* 2. Blocks in candy crash (massive creation and recreation)
* etc... - *

- * + * !#zh + * cc.pool 是一个单例对象,用作为对象缓存池。
+ * 它可以帮助您提高游戏性能,适用于优化对象的反复创建和销毁
+ * 一些常见的用例是:
+ * 1.在游戏中的子弹(死亡很快,频繁创建,对其他对象无副作用)
+ * 2.糖果粉碎传奇中的木块(频繁创建)。 + * 等等.... * @class pool */ cc.pool = /** @lends cc.pool# */{ @@ -49,7 +54,8 @@ cc.pool = /** @lends cc.pool# */{ }, /** - * Put the obj in pool. + * !#en Put the obj in pool. + * !#zh 加入对象到对象池中。 * @method putInPool * @param {Object} obj - The need put in pool object. * @example {@link utils/api/engine/docs/extensions/ccpool/putInPool.js} @@ -70,7 +76,8 @@ cc.pool = /** @lends cc.pool# */{ }, /** - * Check if this kind of obj has already in pool. + * !#en Check if this kind of obj has already in pool. + * !#zh 检查对象池中是否有指定对象的存在。 * @method hasObject * @param {Object} objClass - The check object class. * @returns {Boolean} If this kind of obj is already in pool return true,else return false. @@ -85,7 +92,8 @@ cc.pool = /** @lends cc.pool# */{ }, /** - * Remove the obj if you want to delete it. + * !#en Remove the obj if you want to delete it. + * !#zh 移除在对象池中指定的对象。 * @method removeObject */ removeObject: function (obj) { @@ -105,7 +113,8 @@ cc.pool = /** @lends cc.pool# */{ }, /** - * Get the obj from pool. + * !#en Get the obj from pool. + * !#zh 获取对象池中的指定对象。 * @method getFromPool * @returns {*} Call the reuse function an return the obj. */ @@ -125,7 +134,8 @@ cc.pool = /** @lends cc.pool# */{ }, /** - * Remove all objs in pool and reset the pool. + * !#en Remove all objs in pool and reset the pool. + * !#zh 移除对象池中的所有对象,并且重置对象池。 * @method drainAllPools */ drainAllPools: function () { diff --git a/predefine.js b/predefine.js index d758583c01..fbe631c426 100644 --- a/predefine.js +++ b/predefine.js @@ -24,7 +24,10 @@ ****************************************************************************/ /** - * The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace + * !#en + * The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace. + * !#zh + * Cocos 引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。 * @module cc * @main cc */ From ffb2c9af14e3382549f8be40b69ef9bfa69d20af Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 20 Apr 2016 18:08:16 +0800 Subject: [PATCH 2/2] Label.file change to .font --- cocos2d/core/components/CCLabel.js | 40 +++++++++++++++++------------- cocos2d/core/platform/js.js | 22 ++++++++++------ cocos2d/deprecated.js | 13 ++++++---- index.js | 2 +- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index d642520256..5cd7abac48 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -229,29 +229,35 @@ var Label = cc.Class({ tooltip: 'i18n:COMPONENT.label.wrap', }, + // 这个保存了旧项目的 file 数据 + _N$file: null, + /** - * !#en The font URL of label. - * !#zh 文本字体的 url。 - * @property {cc.Font} file + * !#en The font of label. + * !#zh 文本字体。 + * @property {cc.Font} font */ - file: { - default: null, - type: cc.Font, - tooltip: 'i18n:COMPONENT.label.file', - notify: function () { + font: { + get: function () { + return this._N$file; + }, + set: function (value) { + this._N$file = value; if (this._sgNode) { - if ( typeof this.file === 'string' ) { + if ( typeof value === 'string' ) { cc.warn('Sorry, the cc.Font has been modified from Raw Asset to Asset.' + 'Please load the font asset before using.'); } - var isAsset = this.file instanceof cc.Font; - var fntRawUrl = isAsset ? this.file.rawUrl : ''; - var textureUrl = isAsset ? this.file.texture : ''; + var isAsset = value instanceof cc.Font; + var fntRawUrl = isAsset ? value.rawUrl : ''; + var textureUrl = isAsset ? value.texture : ''; this._sgNode.setFontFileOrFamily(fntRawUrl, textureUrl); } }, + type: cc.Font, + tooltip: 'i18n:COMPONENT.label.font', animatable: false }, @@ -272,7 +278,7 @@ var Label = cc.Class({ set: function(value){ this._isSystemFontUsed = value; if (value) { - this.file = null; + this.font = null; if (this._sgNode) { this._sgNode.setSystemFontUsed(value); } @@ -334,14 +340,14 @@ var Label = cc.Class({ _initSgNode: function () { - if ( typeof this.file === 'string' ) { + if ( typeof this.font === 'string' ) { cc.warn('Sorry, the cc.Font has been modified from Raw Asset to Asset.' + 'Please load the font asset before using.'); } - var isAsset = this.file instanceof cc.Font; - var fntRawUrl = isAsset ? this.file.rawUrl : ''; - var textureUrl = isAsset ? this.file.texture : ''; + var isAsset = this.font instanceof cc.Font; + var fntRawUrl = isAsset ? this.font.rawUrl : ''; + var textureUrl = isAsset ? this.font.texture : ''; this._sgNode = new _ccsg.Label(this.string, fntRawUrl, textureUrl); this._sgNode.retain(); diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js index fcaf3cd1dd..c8148ad220 100644 --- a/cocos2d/core/platform/js.js +++ b/cocos2d/core/platform/js.js @@ -499,19 +499,25 @@ js.set = function (obj, prop, setter, enumerable) { */ js.obsolete = function (obj, obsoleted, newPropName, writable) { var oldName = obsoleted.split('.').slice(-1); - js.get(obj, oldName, function () { + function get () { if (CC_DEV) { cc.warn('"%s" is deprecated, use "%s" instead please.', obsoleted, newPropName); } - return obj[newPropName]; - }); + return this[newPropName]; + } if (writable) { - js.set(obj, oldName, function (value) { - if (CC_DEV) { - cc.warn('"%s" is deprecated, use "%s" instead please.', obsoleted, newPropName); + js.getset(obj, oldName, + get, + function (value) { + if (CC_DEV) { + cc.warn('"%s" is deprecated, use "%s" instead please.', obsoleted, newPropName); + } + this[newPropName] = value; } - obj[newPropName] = value; - }); + ); + } + else { + js.get(obj, oldName, get); } }; diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 309d055660..114d9788a8 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -1,5 +1,9 @@ +var js = cc.js; + +// Label +js.obsolete(cc.Label.prototype, 'cc.Label.file', 'font', true); + if (CC_DEV) { - var js = cc.js; var INFO = cc._LogInfos.deprecated; @@ -546,9 +550,9 @@ if (CC_DEV) { }); //ui - cc.js.obsolete(cc.Layout.prototype, 'Layout.layoutType', 'type'); - cc.js.obsolete(cc.Layout.prototype, 'Layout.ResizeType', 'ResizeMode'); - cc.js.obsolete(cc.Layout.prototype, 'Layout.resize', 'resizeMode'); + js.obsolete(cc.Layout.prototype, 'cc.Layout.layoutType', 'type'); + js.obsolete(cc.Layout.prototype, 'cc.Layout.ResizeType', 'ResizeMode'); + js.obsolete(cc.Layout.prototype, 'cc.Layout.resize', 'resizeMode'); markAsRemoved(cc.Scale9Sprite, [ 'init', @@ -583,4 +587,3 @@ if (CC_DEV) { }); } } - diff --git a/index.js b/index.js index 3900c2e7b1..7a1f4d997a 100644 --- a/index.js +++ b/index.js @@ -72,7 +72,7 @@ if (CC_EDITOR) { if (isMainProcess) { Editor.versions['cocos2d'] = require('./package.json').version; } -else if (CC_DEV) { +else { require('./cocos2d/deprecated'); }