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
*
+ * !#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...
- *