From 3e1484607aa49019beeaa489c63594d9406ad44d Mon Sep 17 00:00:00 2001
From: pandamicro Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays). Schedules a custom selector. unschedule all scheduled callback functions: custom callback functions, and the 'update' callback function. Properties configuration function
+ * !#en
+ * Properties configuration function
* All properties in attrs will be set to the node,
* when the setter of the node is available,
* the property will be set via setter function.
- * Defines the oder in which the nodes are renderer. Returns a copy of the position (x,y) of the node in cocos2d coordinates. (0,0) is the left-bottom corner.
- * Changes the position (x,y) of the node in cocos2d coordinates. Returns a copy of the anchor point.
- * Sets the anchor point in percent. Returns a copy the untransformed size of the node.
- * Sets the untransformed size of the node. "add" logic MUST only be in this method If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
+ * - createNode
+ * - cc.Object._serialize
+ * - cc.Object._deserialize
+ * !#zh
+ * 资源基类,该类可以被实例化。
+ *
+ * 您可能需要重写:
+ * - createNode
+ * - cc.Object._serialize
+ * - cc.Object._deserialize
*
* @class Asset
* @extends RawAsset
@@ -41,9 +49,10 @@ cc.Asset = cc.Class({
properties: {
/**
+ * !#en
* Returns the url of this asset's first raw file, if none of rawFile exists,
* it will returns an empty string.
- *
+ * !#zh 返回该资源的原始文件的 URL,如果不支持 RAW 文件,它将返回一个空字符串。
* @property rawUrl
* @type {String}
* @readOnly
@@ -64,9 +73,10 @@ cc.Asset = cc.Class({
},
/**
+ * !#en
* Returns the url of this asset's raw files, if none of rawFile exists,
* it will returns an empty array.
- *
+ * !#zh 返回该资源的原文件的 URL 数组,如果不支持 RAW 文件,它将返回一个空数组。
* @property rawUrls
* @type {String[]}
* @readOnly
@@ -129,9 +139,12 @@ cc.Asset = cc.Class({
},
/**
- * Create a new node using this asset in the scene.
+ * !#en
+ * Create a new node using this asset in the scene.
* If this type of asset dont have its corresponding node type, this method should be null.
- *
+ * !#zh
+ * 使用该资产在场景中创建一个新节点。
+ * 如果这类资产没有相应的节点类型,该方法应该是空的。
* @method createNode
* @param {Function} callback
* @param {String} callback.error - null or the error info
diff --git a/cocos2d/core/assets/CCAudioClip.js b/cocos2d/core/assets/CCAudioClip.js
index 440c885b32..a08f47f86c 100644
--- a/cocos2d/core/assets/CCAudioClip.js
+++ b/cocos2d/core/assets/CCAudioClip.js
@@ -24,7 +24,8 @@
****************************************************************************/
/**
- * Class for audio data handling.
+ * !#en Class for audio data handling.
+ * !#zh 音频资源类。
* @class AudioClip
* @extends RawAsset
* @constructor
diff --git a/cocos2d/core/assets/CCBitmapFont.js b/cocos2d/core/assets/CCBitmapFont.js
index febdc4039b..f85af284ba 100644
--- a/cocos2d/core/assets/CCBitmapFont.js
+++ b/cocos2d/core/assets/CCBitmapFont.js
@@ -27,7 +27,8 @@
* @module cc
*/
/**
- * Class for BitmapFont handling.
+ * !#en Class for BitmapFont handling.
+ * !#zh 位图字体资源类。
* @class BitmapFont
* @extends RawAsset
* @constructor
diff --git a/cocos2d/core/assets/CCFont.js b/cocos2d/core/assets/CCFont.js
index d70144c620..1eb3c29477 100644
--- a/cocos2d/core/assets/CCFont.js
+++ b/cocos2d/core/assets/CCFont.js
@@ -27,7 +27,8 @@
* @module cc
*/
/**
- * Class for Font handling.
+ * !#en Class for Font handling.
+ * !#zh 字体资源类。
* @class Font
* @extends RawAsset
* @constructor
diff --git a/cocos2d/core/assets/CCPrefab.js b/cocos2d/core/assets/CCPrefab.js
index b2775296ed..0b28d47fd7 100644
--- a/cocos2d/core/assets/CCPrefab.js
+++ b/cocos2d/core/assets/CCPrefab.js
@@ -33,7 +33,8 @@ function visitWrapper (wrapper, visitor) {
}
/**
- * Class for prefab handling.
+ * !#en Class for prefab handling.
+ * !#zh 预制资源类。
* @class Prefab
* @extends Asset
* @constructor
diff --git a/cocos2d/core/assets/CCRawAsset.js b/cocos2d/core/assets/CCRawAsset.js
index 0727b93d78..390108cb50 100644
--- a/cocos2d/core/assets/CCRawAsset.js
+++ b/cocos2d/core/assets/CCRawAsset.js
@@ -25,10 +25,15 @@
var CCObject = require('../platform/CCObject');
/**
+ * !#en
* The base class for registering asset types.
*
* You may want to override:
* - createNode (static)
+ * !#zh
+ * 注册用的资源基类。
+ * 你可能要重写:
+ * - createNode (static)
*
* @class RawAsset
* @extends CCObject
@@ -52,9 +57,12 @@ cc.RawAsset = cc.Class({
statics: {
/**
- * Create a new node in the scene.
+ * !#en
+ * Create a new node in the scene.
* If this type of asset dont have its corresponding node type, this method should be null.
- *
+ * !#zh
+ * 在场景中创建一个新节点。
+ * 如果这类资源没有相应的节点类型,该方法应该是空的。
* @method createNodeByInfo
* @param {Object} Info
* @param {Function} callback
diff --git a/cocos2d/core/assets/CCSceneAsset.js b/cocos2d/core/assets/CCSceneAsset.js
index 95d2fb6088..1988b172d9 100644
--- a/cocos2d/core/assets/CCSceneAsset.js
+++ b/cocos2d/core/assets/CCSceneAsset.js
@@ -24,7 +24,8 @@
****************************************************************************/
/**
- * Class for scene handling.
+ * !#en Class for scene handling.
+ * !#zh 场景资源类。
* @class Scene
* @extends Asset
* @constructor
diff --git a/cocos2d/core/assets/CCScripts.js b/cocos2d/core/assets/CCScripts.js
index 46a9ac433f..3f9568ffdf 100644
--- a/cocos2d/core/assets/CCScripts.js
+++ b/cocos2d/core/assets/CCScripts.js
@@ -24,7 +24,8 @@
****************************************************************************/
/**
- * Class for script handling.
+ * !#en Class for script handling.
+ * !#zh Script 资源类。
* @class _Script
* @extends Asset
* @constructor
@@ -38,7 +39,8 @@ var Script = cc.Class({
cc._Script = Script;
/**
- * Class for JavaScript handling.
+ * !#en Class for JavaScript handling.
+ * !#zh JavaScript 资源类。
* @class _JavaScript
* @extends Asset
* @private
@@ -52,7 +54,8 @@ var JavaScript = cc.Class({
cc._JavaScript = JavaScript;
/**
- * Class for coffee script handling.
+ * !#en Class for coffee script handling.
+ * !#zh CoffeeScript 资源类。
* @class CoffeeScript
* @extends Asset
* @constructor
diff --git a/cocos2d/core/assets/CCSpriteAtlas.js b/cocos2d/core/assets/CCSpriteAtlas.js
index 4d5d85bb4e..a2228f6dfc 100644
--- a/cocos2d/core/assets/CCSpriteAtlas.js
+++ b/cocos2d/core/assets/CCSpriteAtlas.js
@@ -24,7 +24,8 @@
****************************************************************************/
/**
- * Class for sprite atlas handling.
+ * !#en Class for sprite atlas handling.
+ * !#zh 精灵图集资源类。
* @class SpriteAtlas
* @extends RawAsset
* @constructor
diff --git a/cocos2d/core/assets/CCTTFFont.js b/cocos2d/core/assets/CCTTFFont.js
index 5980feb5ce..d0535609aa 100644
--- a/cocos2d/core/assets/CCTTFFont.js
+++ b/cocos2d/core/assets/CCTTFFont.js
@@ -27,7 +27,8 @@
* @module cc
*/
/**
- * Class for TTFFont handling.
+ * !#en Class for TTFFont handling.
+ * !#zh TTF 字体资源类。
* @class TTFFont
* @extends Asset
* @constructor
diff --git a/cocos2d/core/assets/CCTextAsset.js b/cocos2d/core/assets/CCTextAsset.js
index 409ee40296..7a5c69a48c 100644
--- a/cocos2d/core/assets/CCTextAsset.js
+++ b/cocos2d/core/assets/CCTextAsset.js
@@ -24,7 +24,8 @@
****************************************************************************/
/**
- * Class for text file.
+ * !#en Class for text file.
+ * !#zh 文本资源类。
* @class TextAsset
* @extends Asset
* @constructor
From 5ee0d68a07be1e01833a74391436220617cd54bf Mon Sep 17 00:00:00 2001
From: knoxHuang <821686174@qq.com>
Date: Wed, 23 Mar 2016 14:45:42 +0800
Subject: [PATCH 04/17] add Audio API
---
cocos2d/audio/CCAudio.js | 68 +++++++++++++++---------
cocos2d/core/components/CCAudioSource.js | 36 ++++++++-----
2 files changed, 68 insertions(+), 36 deletions(-)
diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js
index 85df6850c2..3c7bb5a03d 100644
--- a/cocos2d/audio/CCAudio.js
+++ b/cocos2d/audio/CCAudio.js
@@ -338,7 +338,8 @@ JS.mixin(cc.Audio.prototype, {
SWC = polyfill.AUTOPLAY;
/**
- * cc.audioEngine is the singleton object, it provide simple audio APIs.
+ * !#en cc.audioEngine is the singleton object, it provide simple audio APIs.
+ * !#zn cc.audioengine是单例对象,它提供了简单的音频接口。
* @class audioEngine
* @static
*/
@@ -348,7 +349,7 @@ JS.mixin(cc.Audio.prototype, {
features: polyfill,
- /**
+ /*
* Indicates whether any background music can be played or not.
* @method willPlayMusic
* @returns {boolean} true if the background music is playing, otherwise false
@@ -356,10 +357,11 @@ JS.mixin(cc.Audio.prototype, {
willPlayMusic: function(){return false;},
/**
- * Play music.
+ * !#en Play music.
+ * !#zh 播放指定音乐,并可以设置是否循环播放。
* @method playMusic
- * @param {String} url The path of the music file without filename extension.
- * @param {Boolean} loop Whether the music loop or not.
+ * @param {String} url - The path of the music file without filename extension.
+ * @param {Boolean} loop - Whether the music loop or not.
* @example
* //example
* cc.audioEngine.playMusic(path, false);
@@ -391,9 +393,10 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Stop playing music.
+ * !#en Stop playing music.
+ * !#zh 停止指定的音乐。
* @method stopMusic
- * @param {Boolean} [releaseData] If release the music data or not.As default value is false.
+ * @param {Boolean} releaseData - If release the music data or not.As default value is false.
* @example
* //example
* cc.audioEngine.stopMusic();
@@ -408,7 +411,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Pause playing music.
+ * !#en Pause playing music.
+ * !#zh 暂停正在播放音乐。
* @method pauseMusic
* @example
* //example
@@ -421,7 +425,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Resume playing music.
+ * !#en Resume playing music.
+ * !#zh 重新播放音乐。
* @method resumeMusic
* @example
* //example
@@ -434,7 +439,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Rewind playing music.
+ * !#en Rewind playing music.
+ * !#zh 倒带播放音乐。
* @method rewindMusic
* @example
* //example
@@ -449,7 +455,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * The volume of the music max value is 1.0,the min value is 0.0 .
+ * !#en The volume of the music max value is 1.0,the min value is 0.0 .
+ * !#zh 获取音量(0.0 ~ 1.0)。
* @method getMusicVolume
* @return {Number}
* @example
@@ -461,7 +468,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Set the volume of music.
+ * !#en Set the volume of music.
+ * !#zh 设置音量(0.0 ~ 1.0)。
* @method setMusicVolume
* @param {Number} volume Volume must be in 0.0~1.0 .
* @example
@@ -482,7 +490,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Whether the music is playing.
+ * !#en Whether the music is playing.
+ * !#zh 音乐是否正在播放。
* @method isMusicPlaying
* @return {Boolean} If is playing return true,or return false.
* @example
@@ -507,7 +516,8 @@ JS.mixin(cc.Audio.prototype, {
_maxAudioInstance: 5,
_effectVolume: 1,
/**
- * Play sound effect.
+ * !#en Play sound effect.
+ * !#zh 播放指定音效,并可以设置是否循环播放。
* @method playEffect
* @param {String} url The path of the sound effect with filename extension.
* @param {Boolean} loop Whether to loop the effect playing, default value is false
@@ -564,7 +574,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Set the volume of sound effects.
+ * !#en Set the volume of sound effects.
+ * !#zh 设置音效音量(0.0 ~ 1.0)。
* @method setEffectsVolume
* @param {Number} volume Volume must be in 0.0~1.0 .
* @example
@@ -589,7 +600,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * The volume of the effects max value is 1.0,the min value is 0.0 .
+ * !#en The volume of the effects max value is 1.0,the min value is 0.0 .
+ * !#zh 获取音效音量(0.0 ~ 1.0)。
* @method getEffectsVolume
* @return {Number}
* @example
@@ -601,7 +613,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Pause playing sound effect.
+ * !#en Pause playing sound effect.
+ * !#zh 暂停指定的音效。
* @method pauseEffect
* @param {Number} audio - The return value of function playEffect.
* @example
@@ -615,7 +628,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Pause all playing sound effect.
+ * !#en Pause all playing sound effect.
+ * !#zh 暂停现在正在播放的所有音效。
* @method pauseAllEffects
* @example
* //example
@@ -634,7 +648,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Resume playing sound effect.
+ * !#en Resume playing sound effect.
+ * !#zh 重新播放指定的音效。
* @method resumeEffect
* @param {Number} audioID - The return value of function playEffect.
* @audioID
@@ -647,7 +662,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Resume all playing sound effect
+ * !#en Resume all playing sound effect.
+ * !#zh 重新播放所有音效。
* @method resumeAllEffects
* @example
* //example
@@ -664,7 +680,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Stop playing sound effect.
+ * !#en Stop playing sound effect.
+ * !#zh 停止播放指定音效。
* @method stopEffect
* @param {Number} audioID - The return value of function playEffect.
* @example
@@ -677,7 +694,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Stop all playing sound effects.
+ * !#en Stop all playing sound effects.
+ * !#zh 停止正在播放的所有音效。
* @method stopAllEffects
* @example
* //example
@@ -694,7 +712,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * Unload the preloaded effect from internal buffer
+ * !#en Unload the preloaded effect from internal buffer.
+ * !#zh 卸载预加载的音效。
* @method unloadEffect
* @param {String} url
* @example
@@ -713,7 +732,8 @@ JS.mixin(cc.Audio.prototype, {
},
/**
- * End music and effects.
+ * !#en End music and effects.
+ * !#zh 释放音频引擎的相关对象。
* @method end
*/
end: function(){
diff --git a/cocos2d/core/components/CCAudioSource.js b/cocos2d/core/components/CCAudioSource.js
index 02a54e893a..5a7f38d37c 100644
--- a/cocos2d/core/components/CCAudioSource.js
+++ b/cocos2d/core/components/CCAudioSource.js
@@ -24,7 +24,8 @@
****************************************************************************/
/**
- * Audio Source.
+ * !#en Audio Source.
+ * !#zh 音频源组件,能对音频剪辑。
* @class AudioSource
* @extends Component
*/
@@ -54,7 +55,8 @@ var AudioSource = cc.Class({
_loop: false,
/**
- * Is the audio source playing (Read Only)
+ * !#en Is the audio source playing (Read Only).
+ * !#zh 该音频剪辑是否正播放(只读)。
* @property isPlaying
* @type {Boolean}
* @readOnly
@@ -68,7 +70,8 @@ var AudioSource = cc.Class({
},
/**
- * The clip of the audio source.
+ * !#en The clip of the audio source.
+ * !#zh 默认要播放的音频剪辑。
* @property clip
* @type {AudioClip}
* @default 1
@@ -86,7 +89,8 @@ var AudioSource = cc.Class({
},
/**
- * The volume of the audio source.
+ * !#en The volume of the audio source.
+ * !#zh 音频源的音量(0.0 ~ 1.0)。
* @property volume
* @type {Number}
* @default 1
@@ -110,7 +114,8 @@ var AudioSource = cc.Class({
},
/**
- * Is the audio source mute?
+ * !#en Is the audio source mute?
+ * !#zh 是否静音音频源。Mute 是设置音量为 0,取消静音是恢复原来的音量。
* @property mute
* @type {Boolean}
* @default false
@@ -145,7 +150,8 @@ var AudioSource = cc.Class({
},
/**
- * Is the audio source looping?
+ * !#en Is the audio source looping?
+ * !#zh 音频源是否循环播放?
* @property loop
* @type {Boolean}
* @default false
@@ -163,7 +169,8 @@ var AudioSource = cc.Class({
},
/**
- * If set to true, the audio source will automatically start playing on onLoad.
+ * !#en If set to true, the audio source will automatically start playing on onLoad.
+ * !#zh 如果设置为true,音频源将在 onLoad 时自动播放。
* @property playOnLoad
* @type {Boolean}
* @default true
@@ -196,7 +203,8 @@ var AudioSource = cc.Class({
},
/**
- * Plays the clip.
+ * !#en Plays the clip.
+ * !#zh 播放音频剪辑。
* @method play
*/
play: function () {
@@ -207,7 +215,8 @@ var AudioSource = cc.Class({
},
/**
- * Stops the clip
+ * !#en Stops the clip.
+ * !#zh 停止当前音频剪辑。
* @method stop
*/
stop: function () {
@@ -215,7 +224,8 @@ var AudioSource = cc.Class({
},
/**
- * Pause the clip.
+ * !#en Pause the clip.
+ * !#zh 暂停当前音频剪辑。
* @method pause
*/
pause: function () {
@@ -223,7 +233,8 @@ var AudioSource = cc.Class({
},
/**
- * Resume the clip.
+ * !#en Resume the clip.
+ * !#zh 重新播放当前音频剪辑。
* @method resume
*/
resume: function () {
@@ -231,7 +242,8 @@ var AudioSource = cc.Class({
},
/**
- * Rewind playing music.
+ * !#en Rewind playing music.
+ * !#zh 倒带播放音乐。
* @method rewind
*/
rewind: function(){
From be89229590300e3e91531e980c1fab4febd7d20f Mon Sep 17 00:00:00 2001
From: knoxHuang <821686174@qq.com>
Date: Wed, 23 Mar 2016 15:28:20 +0800
Subject: [PATCH 05/17] fix Audio API
---
cocos2d/audio/CCAudio.js | 37 +++++++++++++-----------
cocos2d/core/components/CCAudioSource.js | 4 +--
2 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js
index 3c7bb5a03d..e3566d28e8 100644
--- a/cocos2d/audio/CCAudio.js
+++ b/cocos2d/audio/CCAudio.js
@@ -339,7 +339,13 @@ JS.mixin(cc.Audio.prototype, {
/**
* !#en cc.audioEngine is the singleton object, it provide simple audio APIs.
- * !#zn cc.audioengine是单例对象,它提供了简单的音频接口。
+ * !#zn
+ * cc.audioengine是单例对象。
+ * 主要用来播放背景音乐和音效,背景音乐同一时间只能播放一个,而音效则可以同时播放多个。
+ * 注意:
+ * 在 Android 系统浏览器上,不同浏览器,不同版本的效果不尽相同。
+ * 比如说:大多数浏览器都需要用户物理交互才可以开始播放音效,有一些不支持 WebAudio,
+ * 有一些不支持多音轨播放。总之如果对音乐依赖比较强,请做尽可能多的测试。
* @class audioEngine
* @static
*/
@@ -349,16 +355,11 @@ JS.mixin(cc.Audio.prototype, {
features: polyfill,
- /*
- * Indicates whether any background music can be played or not.
- * @method willPlayMusic
- * @returns {boolean} true if the background music is playing, otherwise false
- */
- willPlayMusic: function(){return false;},
-
/**
* !#en Play music.
- * !#zh 播放指定音乐,并可以设置是否循环播放。
+ * !#zh
+ * 播放指定音乐,并可以设置是否循环播放。
+ * 注意:音乐播放接口不支持多音轨,同一时间只能播放一个音乐。
* @method playMusic
* @param {String} url - The path of the music file without filename extension.
* @param {Boolean} loop - Whether the music loop or not.
@@ -394,9 +395,9 @@ JS.mixin(cc.Audio.prototype, {
/**
* !#en Stop playing music.
- * !#zh 停止指定的音乐。
+ * !#zh 停止当前音乐。
* @method stopMusic
- * @param {Boolean} releaseData - If release the music data or not.As default value is false.
+ * @param {Boolean} [releaseData] - If release the music data or not.As default value is false.
* @example
* //example
* cc.audioEngine.stopMusic();
@@ -426,7 +427,7 @@ JS.mixin(cc.Audio.prototype, {
/**
* !#en Resume playing music.
- * !#zh 重新播放音乐。
+ * !#zh 恢复音乐播放。
* @method resumeMusic
* @example
* //example
@@ -440,7 +441,7 @@ JS.mixin(cc.Audio.prototype, {
/**
* !#en Rewind playing music.
- * !#zh 倒带播放音乐。
+ * !#zh 从头开始重新播放当前音乐。
* @method rewindMusic
* @example
* //example
@@ -517,7 +518,9 @@ JS.mixin(cc.Audio.prototype, {
_effectVolume: 1,
/**
* !#en Play sound effect.
- * !#zh 播放指定音效,并可以设置是否循环播放。
+ * !#zh
+ * 播放指定音效,并可以设置是否循环播放。
+ * 注意:在部分不支持多音轨的浏览器上,这个接口会失效,请使用 playMusic
* @method playEffect
* @param {String} url The path of the sound effect with filename extension.
* @param {Boolean} loop Whether to loop the effect playing, default value is false
@@ -649,7 +652,7 @@ JS.mixin(cc.Audio.prototype, {
/**
* !#en Resume playing sound effect.
- * !#zh 重新播放指定的音效。
+ * !#zh 恢复播放指定的音效。
* @method resumeEffect
* @param {Number} audioID - The return value of function playEffect.
* @audioID
@@ -663,7 +666,7 @@ JS.mixin(cc.Audio.prototype, {
/**
* !#en Resume all playing sound effect.
- * !#zh 重新播放所有音效。
+ * !#zh 恢复播放所有之前暂停的所有音效。
* @method resumeAllEffects
* @example
* //example
@@ -733,7 +736,7 @@ JS.mixin(cc.Audio.prototype, {
/**
* !#en End music and effects.
- * !#zh 释放音频引擎的相关对象。
+ * !#zh 停止所有音乐和音效的播放。
* @method end
*/
end: function(){
diff --git a/cocos2d/core/components/CCAudioSource.js b/cocos2d/core/components/CCAudioSource.js
index 5a7f38d37c..a16ee78ca5 100644
--- a/cocos2d/core/components/CCAudioSource.js
+++ b/cocos2d/core/components/CCAudioSource.js
@@ -234,7 +234,7 @@ var AudioSource = cc.Class({
/**
* !#en Resume the clip.
- * !#zh 重新播放当前音频剪辑。
+ * !#zh 恢复播放。
* @method resume
*/
resume: function () {
@@ -243,7 +243,7 @@ var AudioSource = cc.Class({
/**
* !#en Rewind playing music.
- * !#zh 倒带播放音乐。
+ * !#zh 从头开始播放。
* @method rewind
*/
rewind: function(){
From 26dc7622b72a17367515f2665c891386435ccde0 Mon Sep 17 00:00:00 2001
From: zilongshanren
* Node also inherits from {{#crossLink "EventTarget"}}Event Target{{/crossLink}}, it permits Node to dispatch events.
* For events supported by Node, please refer to {{#crossLink "Node.EventType"}}{{/crossLink}}
- *
+ * !#zh
+ * Cocos Creator 场景中的所有节点类。节点也继承了 {{#crossLink "EventTarget"}}EventTarget{{/crossLink}},它允许节点发送事件。
+ * 支持的节点事件,请参阅 {{#crossLink "Node.EventType"}}{{/crossLink}}。
* @class Node
* @extends _BaseNode
*/
@@ -326,10 +329,19 @@ var Node = cc.Class({
properties: {
/**
- * The local active state of this node.
+ * !#en
+ * The local active state of this node.
+ * Note that a Node may be inactive because a parent is not active, even if this returns true.
+ * Use {{#crossLink "Node/activeInHierarchy:property"}}{{/crossLink}} if you want to check if the Node is actually treated as active in the scene.
+ * !#zh
+ * 当前节点的自身激活状态。
+ * 值得注意的是,一个节点的父节点如果不被激活,那么即使它自身设为激活,它仍然无法激活。
+ * 如果你想检查节点在场景中实际的激活状态可以使用 {{#crossLink "Node/activeInHierarchy:property"}}{{/crossLink}}。
* @property active
* @type {Boolean}
* @default true
+ * @example
+ * node.active = false;
*/
active: {
get: function () {
@@ -349,9 +361,12 @@ var Node = cc.Class({
},
/**
- * Indicates whether this node is active in the scene.
+ * !#en Indicates whether this node is active in the scene.
+ * !#zh 表示此节点是否在场景中激活。
* @property activeInHierarchy
* @type {Boolean}
+ * @example
+ * cc.log("activeInHierarchy: " + node.activeInHierarchy);
*/
activeInHierarchy: {
get: function () {
@@ -523,12 +538,20 @@ var Node = cc.Class({
// COMPONENT
/**
- * Returns the component of supplied type if the node has one attached, null if it doesn't.
+ * !#en
+ * Returns the component of supplied type if the node has one attached, null if it doesn't.
* You can also get component in the node by passing in the name of the script.
- *
+ * !#zh
+ * 获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
+ * 传入参数也可以是脚本的名称。
* @method getComponent
* @param {Function|String} typeOrClassName
* @returns {Component}
+ * @example
+ * // get sprite component.
+ * var sprite = node.getComponent(cc.Sprite);
+ * // get custom test calss.
+ * var test = node.getComponent("Test");
*/
getComponent: function (typeOrClassName) {
var constructor = getConstructor(typeOrClassName);
@@ -539,11 +562,14 @@ var Node = cc.Class({
},
/**
- * Returns all components of supplied Type in the node.
- *
+ * !#en Returns all components of supplied type in the node.
+ * !#zh 返回节点上指定类型的所有组件。
* @method getComponents
* @param {Function|String} typeOrClassName
* @returns {Component[]}
+ * @example
+ * var sprites = node.getComponents(cc.Sprite);
+ * var tests = node.getComponents("Test");
*/
getComponents: function (typeOrClassName) {
var constructor = getConstructor(typeOrClassName), components = [];
@@ -555,11 +581,14 @@ var Node = cc.Class({
},
/**
- * Returns the component of supplied type in any of its children using depth first search.
- *
+ * !#en Returns the component of supplied type in any of its children using depth first search.
+ * !#zh 递归查找所有子节点中第一个匹配指定类型的组件。
* @method getComponentInChildren
* @param {Function|String} typeOrClassName
* @returns {Component}
+ * @example
+ * var sprite = node.getComponentInChildren(cc.Sprite);
+ * var Test = node.getComponentInChildren("Test");
*/
getComponentInChildren: function (typeOrClassName) {
var constructor = getConstructor(typeOrClassName);
@@ -571,11 +600,14 @@ var Node = cc.Class({
},
/**
- * Returns the components of supplied type in any of its children using depth first search.
- *
+ * !#en Returns all components of supplied type in any of its children.
+ * !#zh 递归查找所有子节点中指定类型的组件。
* @method getComponentsInChildren
* @param {Function|String} typeOrClassName
* @returns {Component[]}
+ * @example
+ * var sprites = node.getComponentsInChildren(cc.Sprite);
+ * var tests = node.getComponentsInChildren("Test");
*/
getComponentsInChildren: function (typeOrClassName) {
var constructor = getConstructor(typeOrClassName), components = [];
@@ -603,11 +635,14 @@ var Node = cc.Class({
},
/**
- * Adds a component class to the node. You can also add component to node by passing in the name of the script.
- *
+ * !#en Adds a component class to the node. You can also add component to node by passing in the name of the script.
+ * !#zh 向节点添加一个指定类型的组件类,你还可以通过传入脚本的名称来添加组件。
* @method addComponent
* @param {Function|String} typeOrClassName - The constructor or the class name of the component to add
* @returns {Component} - The newly added component
+ * @example
+ * var sprite = node.addComponent(cc.Sprite);
+ * var test = node.addComponent("Test");
*/
addComponent: function (typeOrClassName) {
@@ -728,11 +763,19 @@ var Node = cc.Class({
},
/**
+ * !#en
* Removes a component identified by the given name or removes the component object given.
* You can also use component.destroy() if you already have the reference.
+ * !#zh
+ * 删除节点上的指定组件,传入参数可以是一个组件构造函数或组件名,也可以是已经获得的组件引用。
+ * 如果你已经获得组件引用,你也可以直接调用 component.destroy()
* @method removeComponent
* @param {String|Function|Component} component - The need remove component.
* @deprecated please destroy the component to remove it.
+ * @example
+ * node.removeComponent(cc.Sprite);
+ * var Test = require("Test");
+ * node.removeComponent(Test);
*/
removeComponent: function (component) {
if ( !component ) {
@@ -973,12 +1016,16 @@ var Node = cc.Class({
// EVENTS
/**
- * Register an callback of a specific event type on Node.
+ * !#en
+ * Register a callback of a specific event type on Node.
* Use this method to register touch or mouse event permit propagation based on scene graph,
- * you can propagate the event to the parents or swallow it by calling stopPropagation on the event.
+ * you can propagate the event to the parents or swallow it by calling stopPropagation on the event.
* It's the recommended way to register touch/mouse event for Node,
* please do not use cc.eventManager directly for Node.
- *
+ * !#zh
+ * 在节点上注册指定类型的回调函数,也可以设置 target 用于绑定响应函数的调用者。
+ * 同时您可以将事件派发到父节点或者通过调用 stopPropagation 拦截它。
+ * 推荐使用这种方式来监听节点上的触摸或鼠标事件,请不要在节点上直接使用 cc.eventManager。
* @method on
* @param {String} type - A string representing the event type to listen for.
* @param {Function} callback - The callback that will be invoked when the event is dispatched.
@@ -986,6 +1033,12 @@ var Node = cc.Class({
* @param {Event} callback.param event
* @param {Object} [target] - The target to invoke the callback, can be null
* @return {Function} - Just returns the incoming callback so you can save the anonymous function easier.
+ * @example
+ * // add Node Touch Event
+ * node.on(cc.Node.EventType.TOUCH_START, callback, this.node);
+ * node.on(cc.Node.EventType.TOUCH_MOVE, callback, this.node);
+ * node.on(cc.Node.EventType.TOUCH_END, callback, this.node);
+ * node.on(cc.Node.EventType.TOUCH_END, callback, this.node);
*/
on: function (type, callback, target) {
if (_touchEvents.indexOf(type) !== -1) {
@@ -1023,13 +1076,18 @@ var Node = cc.Class({
},
/**
+ * !#en
* Removes the callback previously registered with the same type, callback, target and or useCapture.
* This method is merely an alias to removeEventListener.
- *
+ * !#zh 删除之前与同类型,回调,目标或 useCapture 注册的回调。
* @method off
* @param {String} type - A string representing the event type being removed.
* @param {Function} callback - The callback to remove.
* @param {Object} [target] - The target to invoke the callback, if it's not given, only callback without target will be removed
+ * @example
+ * // remove Node TOUCH_START Event.
+ * node.on(cc.Node.EventType.TOUCH_START, callback, this.node);
+ * node.off(cc.Node.EventType.TOUCH_START, callback, this.node);
*/
off: function (type, callback, target) {
EventTarget.prototype.off.call(this, type, callback, target);
@@ -1043,10 +1101,12 @@ var Node = cc.Class({
},
/**
- * Removes all callbacks previously registered with the same target.
- *
+ * !#en Removes all callbacks previously registered with the same target.
+ * !#zh 移除目标上的所有注册事件。
* @method targetOff
* @param {Object} target - The target to be searched for all related callbacks
+ * @example
+ * node.targetOff(target);
*/
targetOff: function (target) {
EventTarget.prototype.targetOff.call(this, target);
@@ -1131,12 +1191,19 @@ var Node = cc.Class({
// ACTIONS
/**
+ * !#en
* Executes an action, and returns the action that is executed.
- * The node becomes the action's target. Refer to cc.Action's getTarget()
- * Calling runAction while the node is not active won't have any effect
+ * The node becomes the action's target. Refer to cc.Action's getTarget()
+ * Calling runAction while the node is not active won't have any effect.
+ * !#zh
+ * 执行并返回该执行的动作。该节点将会变成动作的目标。
+ * 调用 runAction 时,节点自身处于不激活状态将不会有任何效果。
* @method runAction
* @param {Action} action
* @return {Action} An Action pointer
+ * @example
+ * var action = cc.scaleTo(0.2, 1, 0.6);
+ * node.runAction(action);
*/
runAction: function (action) {
if (!this.active)
@@ -1152,26 +1219,36 @@ var Node = cc.Class({
},
/**
- * Stops and removes all actions from the running action list .
+ * !#en Stops and removes all actions from the running action list .
+ * !#zh 停止并且移除所有正在运行的动作列表。
* @method stopAllActions
+ * @example
+ * node.stopAllActions();
*/
stopAllActions: function () {
cc.director.getActionManager().removeAllActionsFromTarget(this);
},
/**
- * Stops and removes an action from the running action list.
+ * !#en Stops and removes an action from the running action list.
+ * !#zh 停止并移除指定的动作。
* @method stopAction
* @param {Action} action An action object to be removed.
+ * @example
+ * var action = cc.scaleTo(0.2, 1, 0.6);
+ * node.stopAction(action);
*/
stopAction: function (action) {
cc.director.getActionManager().removeAction(action);
},
/**
- * Removes an action from the running action list by its tag.
+ * !#en Removes an action from the running action list by its tag.
+ * !#zh 停止并且移除指定标签的动作。
* @method stopActionByTag
* @param {Number} tag A tag that indicates the action to be removed.
+ * @example
+ * node.stopAction(1);
*/
stopActionByTag: function (tag) {
if (tag === cc.Action.TAG_INVALID) {
@@ -1182,11 +1259,14 @@ var Node = cc.Class({
},
/**
- * Returns an action from the running action list by its tag.
+ * !#en Returns an action from the running action list by its tag.
+ * !#zh 通过标签获取指定动作。
* @method getActionByTag
* @see cc.Action#getTag and cc.Action#setTag
* @param {Number} tag
* @return {Action} The action object with the given tag.
+ * @example
+ * var action = node.getActionByTag(1);
*/
getActionByTag: function (tag) {
if (tag === cc.Action.TAG_INVALID) {
@@ -1196,12 +1276,23 @@ var Node = cc.Class({
cc.director.getActionManager().getActionByTag(tag, this);
},
- /**
+ /**
+ * !#en
+ * Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
* 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.
+ * 例如:
+ * - 如果你正在运行 7 个动作中的 1 个 Sequence,它将返回 1。
+ * - 如果你正在运行 2 个动作中的 7 个 Sequence,它将返回 7。
+ *
* @method getNumberOfRunningActions
* @return {Number} The number of actions that are running plus the ones that are schedule to run
+ * @example
+ * var count = node.getNumberOfRunningActions();
+ * cc.log("Running Action Count: " + count);
*/
getNumberOfRunningActions: function () {
cc.director.getActionManager().numberOfRunningActionsInTarget(this);
@@ -1252,6 +1343,7 @@ if (cc.sys.isNative) {
}
/**
+ *
* @event position-changed
* @param {Event} event
* @param {Vec2} event.detail - old position
@@ -1301,8 +1393,11 @@ if (cc.sys.isNative) {
* @param {Event} event
*/
/**
+ * !#en
* Note: This event is only emitted from the top most node whose active value did changed,
* not including its child nodes.
+ * !#zh
+ * 注意:此节点激活时,此事件仅从最顶部的节点发出。
* @event active-in-hierarchy-changed
* @param {Event} event
*/
diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js
index 19e33fc5ef..1c5ee382f4 100644
--- a/cocos2d/core/components/CCComponent.js
+++ b/cocos2d/core/components/CCComponent.js
@@ -181,10 +181,15 @@ var _callLateUpdate = CC_EDITOR ? function (event) {
var idGenerater = new IdGenerater('Comp');
/**
- * Base class for everything attached to Node(Entity).
- *
+ * !#en
+ * Base class for everything attached to Node(Entity).
+ *
* NOTE: Not allowed to use construction parameters for Component's subclasses,
* because Component is created by the engine.
+ * !#zh
+ * 所有附加到节点的基类。
+ *
+ * 注意:不允许使用组件的子类构造参数,因为组件是由引擎创建的。
*
* @class Component
* @extends Object
@@ -211,9 +216,12 @@ var Component = cc.Class({
properties: {
/**
- * The node this component is attached to. A component is always attached to a node.
+ * !#en The node this component is attached to. A component is always attached to a node.
+ * !#zh 该组件被附加到的节点。组件总会附加到一个节点。
* @property node
* @type {Node}
+ * @example
+ * cc.log(comp.node);
*/
node: {
default: null,
@@ -243,10 +251,13 @@ var Component = cc.Class({
},
/**
- * The uuid for editor
+ * !#en The uuid for editor.
+ * !#zh 组件的 uuid,用于编辑器。
* @property uuid
* @type {String}
* @readOnly
+ * @example
+ * cc.log(comp.uuid);
*/
uuid: {
get: function () {
@@ -295,10 +306,14 @@ var Component = cc.Class({
_enabled: true,
/**
- * indicates whether this component is enabled or not.
+ * !#en indicates whether this component is enabled or not.
+ * !#zh 表示该组件自身是否启用。
* @property enabled
* @type {Boolean}
* @default true
+ * @example
+ * comp.enabled = true;
+ * cc.log(comp.enabled);
*/
enabled: {
get: function () {
@@ -316,10 +331,13 @@ var Component = cc.Class({
},
/**
- * indicates whether this component is enabled and its node is also active in the hierarchy.
+ * !#en indicates whether this component is enabled and its node is also active in the hierarchy.
+ * !#zh 表示该组件是否被启用并且所在的节点也处于激活状态。。
* @property enabledInHierarchy
* @type {Boolean}
* @readOnly
+ * @example
+ * cc.log(comp.enabledInHierarchy);
*/
enabledInHierarchy: {
get: function () {
@@ -329,9 +347,13 @@ var Component = cc.Class({
},
/**
+ * !#en TODO
+ * !#zh onLoad 是否被调用。
* @property _isOnLoadCalled
* @type {Boolean}
* @readOnly
+ * @example
+ * cc.log(_isOnLoadCalled);
*/
_isOnLoadCalled: {
get: function () {
@@ -358,43 +380,50 @@ var Component = cc.Class({
// We provide Pre methods, which are called right before something happens, and Post methods which are called right after something happens.
/**
- * Update is called every frame, if the Component is enabled.
+ * !#en Update is called every frame, if the Component is enabled.
+ * !#zh 如果该组件启用,则每帧调用 update。
* @method update
*/
update: null,
/**
- * LateUpdate is called every frame, if the Component is enabled.
+ * !#en LateUpdate is called every frame, if the Component is enabled.
+ * !#zh 如果该组件启用,则每帧调用 LateUpdate。
* @method lateUpdate
*/
lateUpdate: null,
/**
- * When attaching to an active node or its node first activated
+ * !#en When attaching to an active node or its node first activated.
+ * !#zh 当附加到一个激活的节点上或者其节点第一次激活时候调用。
* @method onLoad
*/
onLoad: null,
/**
- * Called before all scripts' update if the Component is enabled
+ * !#en Called before all scripts' update if the Component is enabled.
+ * !#zh 如果该组件启用,则在所有组件的 update 之前调用。
* @method start
*/
start: null,
/**
- * Called when this component becomes enabled and its node becomes active
+ * !#en Called when this component becomes enabled and its node is active.
+ * !#zh 当该组件被启用,并且它的节点也激活时。
* @method onEnable
*/
onEnable: null,
/**
- * Called when this component becomes disabled or its node becomes inactive
+ * !#en Called when this component becomes disabled or its node becomes inactive.
+ * !#zh 当该组件被禁用或节点变为无效时调用。
* @method onDisable
*/
onDisable: null,
/**
- * Called when this component will be destroyed.
+ * !#en Called when this component will be destroyed.
+ * !#zh 当该组件被销毁时调用
* @method onDestroy
*/
onDestroy: null,
@@ -411,57 +440,81 @@ var Component = cc.Class({
// PUBLIC
/**
- * Adds a component class to the node. You can also add component to node by passing in the name of the
- * script.
+ * !#en Adds a component class to the node. You can also add component to node by passing in the name of the script.
+ * !#zh 向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。
*
* @method addComponent
* @param {Function|String} typeOrTypename - the constructor or the class name of the component to add
* @return {Component} - the newly added component
+ * @example
+ * var sprite = node.addComponent(cc.Sprite);
+ * var test = node.addComponent("Test");
*/
addComponent: function (typeOrTypename) {
return this.node.addComponent(typeOrTypename);
},
/**
- * Returns the component of supplied type if the node has one attached, null if it doesn't. You can also get
- * component in the node by passing in the name of the script.
+ * !#en
+ * Returns the component of supplied type if the node has one attached, null if it doesn't.
+ * You can also get component in the node by passing in the name of the script.
+ * !#zh
+ * 获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
+ * 传入参数也可以是脚本的名称。
*
* @method getComponent
* @param {Function|String} typeOrClassName
* @return {Component}
+ * @example
+ * // get sprite component.
+ * var sprite = node.getComponent(cc.Sprite);
+ * // get custom test calss.
+ * var test = node.getComponent("Test");
*/
getComponent: function (typeOrClassName) {
return this.node.getComponent(typeOrClassName);
},
/**
- * Returns all components of supplied Type in the node.
+ * !#en Returns all components of supplied Type in the node.
+ * !#zh 返回节点上指定类型的所有组件。
*
* @method getComponents
* @param {Function|String} typeOrClassName
* @return {Component[]}
+ * @example
+ * var sprites = node.getComponents(cc.Sprite);
+ * var tests = node.getComponents("Test");
*/
getComponents: function (typeOrClassName) {
return this.node.getComponents(typeOrClassName);
},
/**
- * Returns the component of supplied type in any of its children using depth first search.
+ * !#en Returns the component of supplied type in any of its children using depth first search.
+ * !#zh 递归查找所有子节点中第一个匹配指定类型的组件。
*
* @method getComponentInChildren
* @param {Function|String} typeOrClassName
* @returns {Component}
+ * @example
+ * var sprite = node.getComponentInChildren(cc.Sprite);
+ * var Test = node.getComponentInChildren("Test");
*/
getComponentInChildren: function (typeOrClassName) {
return this.node.getComponentInChildren(typeOrClassName);
},
/**
- * Returns the components of supplied type in any of its children using depth first search.
+ * !#en Returns the components of supplied type in any of its children using depth first search.
+ * !#zh 递归查找所有子节点中指定类型的组件。
*
* @method getComponentsInChildren
* @param {Function|String} typeOrClassName
* @returns {Component[]}
+ * @example
+ * var sprites = node.getComponentsInChildren(cc.Sprite);
+ * var tests = node.getComponentsInChildren("Test");
*/
getComponentsInChildren: function (typeOrClassName) {
return this.node.getComponentsInChildren(typeOrClassName);
@@ -539,8 +592,12 @@ var Component = cc.Class({
// VIRTUAL
/**
+ * !#en
* If the component's bounding box is different from the node's, you can implement this method to supply
* a custom axis aligned bounding box (AABB), so the editor's scene view can perform hit test properly.
+ * !#zh
+ * 如果组件的包围盒与节点不同,您可以实现该方法以提供自定义的轴向对齐的包围盒(AABB),
+ * 以便编辑器的场景视图可以正确地执行点选测试。
*
* @method _getLocalBounds
* @param {Rect} out_rect - the Rect to receive the bounding box
@@ -548,27 +605,44 @@ var Component = cc.Class({
_getLocalBounds: null,
/**
+ * !#en
* onRestore is called after the user clicks the Reset item in the Inspector's context menu or performs
- * an undo operation on this component.
- *
- * If the component contains the "internal state", short for "temporary member variables which not included
- * in its CCClass properties", then you may need to implement this function.
- *
- * The editor will call the getset accessors of your component to record/restore the component's state
- * for undo/redo operation. However, in extreme cases, it may not works well. Then you should implement
- * this function to manually synchronize your component's "internal states" with its public properties.
- * Once you implement this function, all the getset accessors of your component will not be called when
- * the user performs an undo/redo operation. Which means that only the properties with default value
- * will be recorded or restored by editor.
- *
- * Similarly, the editor may failed to reset your component correctly in extreme cases. Then if you need
- * to support the reset menu, you should manually synchronize your component's "internal states" with its
- * properties in this function. Once you implement this function, all the getset accessors of your component
- * will not be called during reset operation. Which means that only the properties with default value
+ * an undo operation on this component.
+ *
+ * If the component contains the "internal state", short for "temporary member variables which not included
+ * in its CCClass properties", then you may need to implement this function.
+ *
+ * The editor will call the getset accessors of your component to record/restore the component's state
+ * for undo/redo operation. However, in extreme cases, it may not works well. Then you should implement
+ * this function to manually synchronize your component's "internal states" with its public properties.
+ * Once you implement this function, all the getset accessors of your component will not be called when
+ * the user performs an undo/redo operation. Which means that only the properties with default value
+ * will be recorded or restored by editor.
+ *
+ * Similarly, the editor may failed to reset your component correctly in extreme cases. Then if you need
+ * to support the reset menu, you should manually synchronize your component's "internal states" with its
+ * properties in this function. Once you implement this function, all the getset accessors of your component
+ * will not be called during reset operation. Which means that only the properties with default value
* will be reset by editor.
*
* This function is only called in editor mode.
- *
+ * !#zh
+ * onRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。
+ *
+ * 如果组件包含了“内部状态”(不在 CCClass 属性中定义的临时成员变量),那么你可能需要实现该方法。
+ *
+ * 编辑器执行撤销/重做操作时,将调用组件的 get set 来录制和还原组件的状态。
+ * 然而,在极端的情况下,它可能无法良好运作。
+ * 那么你就应该实现这个方法,手动根据组件的属性同步“内部状态”。
+ * 一旦你实现这个方法,当用户撤销或重做时,组件的所有 get set 都不会再被调用。
+ * 这意味着仅仅指定了默认值的属性将被编辑器记录和还原。
+ *
+ * 同样的,编辑可能无法在极端情况下正确地重置您的组件。
+ * 于是如果你需要支持组件重置菜单,你需要在该方法中手工同步组件属性到“内部状态”。
+ * 一旦你实现这个方法,组件的所有 get set 都不会在重置操作时被调用。
+ * 这意味着仅仅指定了默认值的属性将被编辑器重置。
+ *
+ * 此方法仅在编辑器下会被调用。
* @method onRestore
*/
onRestore: null,
@@ -685,13 +759,20 @@ var Component = cc.Class({
},
/**
- *
- * If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.
+ * If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.
+ * !#zh
+ * 调度一个自定义的选择器。
+ * 如果选择器已调度,那么间隔参数将无需再次调度它更新。
* @method schedule
* @param {function} callback The callback function
* @param {Number} [interval=0] Tick interval in seconds. 0 means tick every frame. If interval = 0, it's recommended to use scheduleUpdate() instead.
* @param {Number} [repeat=cc.macro.REPEAT_FOREVER] The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.
* @param {Number} [delay=0] The amount of time that the first tick will wait before execution.
+ * @example
+ * var squashAction = cc.scaleTo(0.2, 1, 0.6);
+ * this.seq = cc.sequence(squashAction);
*/
schedule: function (callback, interval, repeat, delay) {
cc.assert(callback, cc._LogInfos.Node.schedule);
@@ -705,21 +786,28 @@ var Component = cc.Class({
},
/**
- * Schedules a callback function that runs only once, with a delay of 0 or larger
+ * !#en Schedules a callback function that runs only once, with a delay of 0 or larger.
+ * !#zh 调度一个只运行一次的选择器,伴随着一个 0 或者更大的延时。
* @method scheduleOnce
* @see cc.Node#schedule
* @param {function} callback A function wrapped as a selector
* @param {Number} [delay=0] The amount of time that the first tick will wait before execution.
+ * @example
+ * var squashAction = cc.scaleTo(0.2, 1, 0.6);
+ * this.seq = cc.scheduleOnce(squashAction);
*/
scheduleOnce: function (callback, delay) {
this.schedule(callback, 0, 0, delay);
},
/**
- * Unschedules a custom callback function.
+ * !#en Unschedules a custom callback function.
+ * !#zh 取消调度一个自定义的选择器。
* @method unschedule
* @see cc.Node#schedule
* @param {function} callback_fn A function wrapped as a selector
+ * @example
+ * this.unschedule(_callback);
*/
unschedule: function (callback_fn) {
if (!callback_fn)
@@ -729,9 +817,13 @@ var Component = cc.Class({
},
/**
- *
- * Actions are not affected by this method.
+ * Actions are not affected by this method.
+ * !#zh 取消调度所有已调度的回调函数:定制的回调函数,而 'update' 回调函数。动作不受此影响方法。
* @method unscheduleAllCallbacks
+ * @example
+ * this.unscheduleAllCallbacks();
*/
unscheduleAllCallbacks: function () {
cc.director.getScheduler().unscheduleAllForTarget(this);
diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js
index a55b208d8a..3e15ef5ba2 100644
--- a/cocos2d/core/event/event-target.js
+++ b/cocos2d/core/event/event-target.js
@@ -175,7 +175,7 @@ JS.mixin(EventTarget.prototype, {
* When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE.
* Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
* @return {Function} - Just returns the incoming callback so you can save the anonymous function easier.
- * @exmaple
+ * @example
* node.on(cc.Node.EventType.TOUCH_END, function (event) {
* cc.log("this is callback");
* }, node);
@@ -222,7 +222,7 @@ JS.mixin(EventTarget.prototype, {
* If not specified, useCapture defaults to false. If a callback was registered twice,
* one with capture and one without, each must be removed separately. Removal of a capturing callback
* does not affect a non-capturing version of the same listener, and vice versa.
- * @exmaple
+ * @example
* // register touchEnd eventListener
* var touchEnd = node.on(cc.Node.EventType.TOUCH_END, function (event) {
* cc.log("this is callback");
@@ -283,7 +283,7 @@ JS.mixin(EventTarget.prototype, {
* from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE.
* When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE.
* Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
- * @exmaple
+ * @example
* node.once(cc.Node.EventType.TOUCH_END, function (event) {
* cc.log("this is callback");
* }, node);
diff --git a/cocos2d/core/platform/CCObject.js b/cocos2d/core/platform/CCObject.js
index dca5d045a3..fcb356c59f 100644
--- a/cocos2d/core/platform/CCObject.js
+++ b/cocos2d/core/platform/CCObject.js
@@ -65,13 +65,15 @@ CCObject.Flags = {
//ToDestroy: ToDestroy,
/**
- * The object will not be saved.
+ * !#en The object will not be saved.
+ * !#zh 该对象将不会被保存。
* @property {Number} DontSave
*/
DontSave: DontSave,
/**
- * The object will not be saved when building a player.
+ * !#en The object will not be saved when building a player.
+ * !#zh 构建项目时,该对象将不会被保存。
* @property {Number} EditorOnly
*/
EditorOnly: EditorOnly,
@@ -79,7 +81,8 @@ CCObject.Flags = {
Dirty: Dirty,
/**
- * Dont destroy automatically when loading a new scene.
+ * !#en Dont destroy automatically when loading a new scene.
+ * !#zh 加载一个新场景时,不自动删除该对象
* @property DontDestroy
* @private
*/
@@ -92,8 +95,12 @@ CCObject.Flags = {
Destroying: Destroying,
/**
+ * !#en
* Hide in game and hierarchy.
- * This flag is readonly, it can only be used as an argument of scene.addEntity() or Entity.createWithFlags()
+ * This flag is readonly, it can only be used as an argument of scene.addEntity() or Entity.createWithFlags().
+ * !#zh
+ * 在游戏和层级中隐藏该对象。
+ * 该标记只读,它只能被用作 scene.addEntity()的一个参数。
* @property {Number} HideInGame
*/
HideInGame: HideInGame,
@@ -101,14 +108,19 @@ CCObject.Flags = {
// FLAGS FOR EDITOR
/**
- * This flag is readonly, it can only be used as an argument of scene.addEntity() or Entity.createWithFlags()
+ * !#en This flag is readonly, it can only be used as an argument of scene.addEntity() or Entity.createWithFlags().
+ * !#zh 该标记只读,它只能被用作 scene.addEntity()的一个参数。
* @property {Number} HideInEditor
*/
HideInEditor: HideInEditor,
/**
+ * !#en
* Hide in game view, hierarchy, and scene view... etc.
- * This flag is readonly, it can only be used as an argument of scene.addEntity() or Entity.createWithFlags()
+ * This flag is readonly, it can only be used as an argument of scene.addEntity() or Entity.createWithFlags().
+ * !#zh
+ * 在游戏视图,层级,场景视图等等...中隐藏该对象。
+ * 该标记只读,它只能被用作 scene.addEntity()的一个参数。
* @property {Number} Hide
*/
Hide: Hide,
@@ -184,9 +196,12 @@ if (CC_EDITOR) {
var prototype = CCObject.prototype;
/**
- * The name of the object.
+ * !#en The name of the object.
+ * !#zh 该对象的名称。
* @property {String} name
* @default ""
+ * @example
+ * obj.name = "New Obj";
*/
JS.getset(prototype, 'name',
function () {
@@ -198,10 +213,13 @@ JS.getset(prototype, 'name',
);
/**
- * Indicates whether the object is not yet destroyed
+ * !#en Indicates whether the object is not yet destroyed.
+ * !#zh 表示该对象是否可用(被销毁后将不可用)。
* @property {Boolean} isValid
* @default true
* @readOnly
+ * @example
+ * cc.log(obj.isValid);
*/
JS.get(prototype, 'isValid', function () {
return !(this._objFlags & Destroyed);
@@ -210,14 +228,20 @@ JS.get(prototype, 'isValid', function () {
var deferredDestroyTimer = null;
/**
- * Destroy this Object, and release all its own references to other objects.
- *
- * After destroy, this CCObject is not usable any more.
+ * !#en
+ * Destroy this Object, and release all its own references to other objects.
+ *
+ * After destroy, this CCObject is not usable any more.
* You can use cc.isValid(obj) (or obj.isValid if obj is non-nil) to check whether the object is destroyed before
* accessing it.
- *
+ * !#zh
+ * 销毁该对象,并释放所有它对其它对象的引用。
+ * 销毁后,CCObject 不再可用。
+ * 您可以在访问对象之前使用 cc.isValid(obj)(或 obj.isValid 如果 obj 不为 null)来检查对象是否已被销毁。
* @method destroy
* @return {Boolean} whether it is the first time the destroy being called
+ * @example
+ * obj.destroy();
*/
prototype.destroy = function () {
if (this._objFlags & Destroyed) {
@@ -239,10 +263,15 @@ prototype.destroy = function () {
if (CC_DEV) {
/**
+ * !#en
* In fact, Object's "destroy" will not trigger the destruct operation in Firebal Editor.
* The destruct operation will be executed by Undo system later.
- *
+ * !#zh
+ * 事实上,对象的 “destroy” 不会在编辑器中触发析构操作,
+ * 析构操作将在 Undo 系统中延后执行。
* @method realDestroyInEditor
+ * @example
+ * cc.log(obj.realDestroyInEditor());
*/
prototype.realDestroyInEditor = function () {
if (this._objFlags & Destroyed) {
@@ -342,10 +371,13 @@ prototype._deserialize = null;
*/
/**
- * Checks whether the object is non-nil and not yet destroyed
+ * !#en Checks whether the object is non-nil and not yet destroyed.
+ * !#zh 检查该对象是否不为 null 并且尚未销毁。
* @method isValid
* @param {any} value
* @return {Boolean} whether is valid
+ * @example
+ * cc.log(cc.isValid(target));
*/
cc.isValid = function (value) {
if (typeof value === 'object') {
diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js
index 271a2c031f..20782b3499 100644
--- a/cocos2d/core/utils/base-node.js
+++ b/cocos2d/core/utils/base-node.js
@@ -99,9 +99,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
// API
/**
- * Name of node
+ * !#en Name of node.
+ * !#zh 该节点名称。
* @property name
* @type {String}
+ * @example
+ * node.name = "New Node";
+ * cc.log("Node Name: " + node.name);
*/
name: {
get: function () {
@@ -113,10 +117,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * The parent of the node.
+ * !#en The parent of the node.
+ * !#zh 该节点的父节点。
* @property parent
* @type {Node}
* @default null
+ * @example
+ * node.parent = newNode;
*/
parent: {
get: function () {
@@ -168,10 +175,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * The uuid for editor, will be stripped before building project
+ * !#en The uuid for editor, will be stripped before building project.
+ * !#zh 用于编辑器使用的 uuid,在构建项目之前将会被剔除。
* @property uuid
* @type {String}
* @readOnly
+ * @example
+ * cc.log("Node Uuid: " + node.uuid);
*/
uuid: {
get: function () {
@@ -184,9 +194,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Skew x
+ * !#en Skew x
+ * !#zh 该节点 Y 轴倾斜角度。
* @property skewX
* @type {Number}
+ * @example
+ * node.skewX = 0;
+ * cc.log("Node SkewX: " + node.skewX);
*/
skewX: {
get: function () {
@@ -199,9 +213,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Skew y
+ * !#en Skew y
+ * !#zh 该节点 X 轴倾斜角度。
* @property skewY
* @type {Number}
+ * @example
+ * node.skewY = 0;
+ * cc.log("Node SkewY: " + node.skewY);
*/
skewY: {
get: function () {
@@ -214,9 +232,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Z order in depth which stands for the drawing order.
+ * !#en Z order in depth which stands for the drawing order.
+ * !#zh 该节点渲染排序的 Z 轴深度。
* @property zIndex
* @type {Number}
+ * @example
+ * node.zIndex = 1;
+ * cc.log("Node zIndex: " + node.zIndex);
*/
zIndex: {
get: function () {
@@ -229,9 +251,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Rotation of node
+ * !#en Rotation of node.
+ * !#zh 该节点旋转角度。
* @property rotation
* @type {Number}
+ * @example
+ * node.rotation = 90;
+ * cc.log("Node Rotation: " + node.rotation);
*/
rotation: {
get: function () {
@@ -250,9 +276,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Rotation on x axis
+ * !#en Rotation on x axis.
+ * !#zh 该节点 X 轴旋转角度。
* @property rotationX
* @type {Number}
+ * @example
+ * node.rotationX = 45;
+ * cc.log("Node Rotation X: " + node.rotationX);
*/
rotationX: {
get: function () {
@@ -269,9 +299,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Rotation on y axis
+ * !#en Rotation on y axis.
+ * !#zh 该节点 Y 轴旋转角度。
* @property rotationY
* @type {Number}
+ * @example
+ * node.rotationY = 45;
+ * cc.log("Node Rotation Y: " + node.rotationY);
*/
rotationY: {
get: function () {
@@ -290,9 +324,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Scale on x axis
+ * !#en Scale on x axis.
+ * !#zh 节点 X 轴缩放。
* @property scaleX
* @type {Number}
+ * @example
+ * node.scaleX = 0.5;
+ * cc.log("Node Scale X: " + node.scaleX);
*/
scaleX: {
get: function () {
@@ -309,9 +347,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Scale on y axis
+ * !#en Scale on y axis.
+ * !#zh 节点 Y 轴缩放。
* @property scaleY
* @type {Number}
+ * @example
+ * node.scaleY = 0.5;
+ * cc.log("Node Scale Y: " + node.scaleY);
*/
scaleY: {
get: function () {
@@ -328,9 +370,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * x axis position of node.
+ * !#en x axis position of node.
+ * !#zh 节点 X 轴坐标。
* @property x
* @type {Number}
+ * @example
+ * node.x = 100;
+ * cc.log("Node Position X: " + node.x);
*/
x: {
get: function () {
@@ -357,9 +403,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * y axis position of node.
+ * !#en y axis position of node.
+ * !#zh 节点 Y 轴坐标。
* @property y
* @type {Number}
+ * @example
+ * node.y = 100;
+ * cc.log("Node Position Y: " + node.y);
*/
y: {
get: function () {
@@ -386,10 +436,16 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * All children nodes
+ * !#en All children nodes.
+ * !#zh 节点的所有子节点。
* @property children
* @type {Node[]}
* @readOnly
+ * @example
+ * var children = node.children;
+ * for (var i = 0; i < children.lenght; ++i) {
+ * cc.log("Node: " + children[i]);
+ * }
*/
children: {
get: function () {
@@ -398,10 +454,14 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * All children nodes.
+ * !#en All children nodes.
+ * !#zh 节点的子节点数量。
* @property childrenCount
* @type {Number}
* @readOnly
+ * @example
+ * var count = node.childrenCount;
+ * cc.log("Node Children Count: " + count);
*/
childrenCount: {
get: function () {
@@ -410,9 +470,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Anchor point's position on x axis.
+ * !#en Anchor point's position on x axis.
+ * !#zh 节点 X 轴锚点位置。
* @property anchorX
* @type {Number}
+ * @example
+ * node.anchorX = 0;
*/
anchorX: {
get: function () {
@@ -429,9 +492,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Anchor point's position on y axis.
+ * !#en Anchor point's position on y axis.
+ * !#zh 节点 Y 轴锚点位置。
* @property anchorY
* @type {Number}
+ * @example
+ * node.anchorY = 0;
*/
anchorY: {
get: function () {
@@ -448,9 +514,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Width of node.
+ * !#en Width of node.
+ * !#zh 节点宽度。
* @property width
* @type {Number}
+ * @example
+ * node.width = 100;
*/
width: {
get: function () {
@@ -476,9 +545,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Height of node.
+ * !#en Height of node.
+ * !#zh 节点高度。
* @property height
* @type {Number}
+ * @example
+ * node.height = 100;
*/
height: {
get: function () {
@@ -528,9 +600,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Tag of node.
+ * !#en Tag of node.
+ * !#zh 节点标签。
* @property tag
* @type {Number}
+ * @example
+ * node.tag = 1001;
*/
tag: {
get: function () {
@@ -543,9 +618,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Opacity of node, default value is 255.
+ * !#en Opacity of node, default value is 255.
+ * !#zh 节点透明度,默认值为 255。
* @property opacity
* @type {Number}
+ * @example
+ * node.opacity = 255;
*/
opacity: {
get: function () {
@@ -564,9 +642,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Indicate whether node's opacity value affect its child nodes, default value is false.
+ * !#en Indicate whether node's opacity value affect its child nodes, default value is false.
+ * !#zh 节点的不透明度值是否影响其子节点,默认值为 false。
* @property cascadeOpacity
* @type {Boolean}
+ * @example
+ * cc.log("CascadeOpacity: " + node.cascadeOpacity);
*/
cascadeOpacity: {
get: function () {
@@ -582,9 +663,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Color of node, default value is white: (255, 255, 255).
+ * !#en Color of node, default value is white: (255, 255, 255).
+ * !#zh 节点颜色。默认为白色,数值为:(255,255,255)。
* @property color
* @type {Color}
+ * @example
+ * node.color = new cc.Color(255, 255, 255);
*/
color: {
get: function () {
@@ -664,7 +748,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
_onOpacityModifyRGBChanged: null,
- /**
+ /*
* Initializes the instance of cc.Node
* @method init
* @returns {Boolean} Whether the initialization was successful.
@@ -675,13 +759,17 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- *
- * Nodes that have a Global Z Order lower, are renderer first.
- *
- * In case two or more nodes have the same Global Z Order, the oder is not guaranteed.
- * The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used.
- *
- * By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes.
- *
- * Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order.
- *
- * Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their ancestors.
- * And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode.
+ * In case two or more nodes have the same Global Z Order, the oder is not guaranteed.
+ * The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used.
+ *
+ * By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes.
+ *
+ * Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order.
+ *
+ * Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their ancestors.
+ * And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode.
+ * !#zh
+ * 定义节点的渲染顺序。
+ * 节点具有全局 Z 顺序,顺序越小的节点,最先渲染。
+ *
+ * 假设两个或者更多的节点拥有相同的全局 Z 顺序,那么渲染顺序无法保证。
+ * 唯一的例外是如果节点的全局 Z 顺序为零,那么场景中的顺序是可以使用默认的。
+ *
+ * 所有的节点全局 Z 顺序都是零。这就是说,默认使用场景中的顺序来渲染节点。
+ *
+ * 全局 Z 顺序是非常有用的当你需要渲染节点按照不同的顺序而不是场景顺序。
+ *
+ * 局限性: 全局 Z 顺序不能够被拥有继承 “SpriteBatchNode” 的节点使用。
+ * 并且如果 “ClippingNode” 是其中之一的上代,那么 “global Z order” 将会和 “ClippingNode” 有关。
* @method setGlobalZOrder
* @param {Number} globalZOrder
+ * @example
+ * node.setGlobalZOrder(0);
*/
setGlobalZOrder: function (globalZOrder) {
this._globalZOrder = globalZOrder;
@@ -711,9 +815,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Return the Node's Global Z Order.
+ * !#en Return the Node's Global Z Order.
+ * !#zh 获取节点的全局 Z 顺序。
* @method getGlobalZOrder
* @returns {number} The node's global Z order
+ * @example
+ * cc.log("Global Z Order: " + node.getGlobalZOrder());
*/
getGlobalZOrder: function () {
this._globalZOrder = this._sgNode.getGlobalZOrder();
@@ -721,10 +828,14 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
+ * !#en
* Returns the scale factor of the node.
* Assertion will fail when _scaleX != _scaleY.
+ * !#zh 获取节点的缩放。当 X 轴和 Y 轴有相同的缩放数值时。
* @method getScale
* @return {Number} The scale factor
+ * @example
+ * cc.log("Node Scale: " + node.getScale());
*/
getScale: function () {
if (this._scaleX !== this._scaleY)
@@ -733,10 +844,14 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time.
+ * !#en Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time.
+ * !#zh 设置节点的缩放比例,默认值为 1.0。这个函数可以在同一时间修改 X 和 Y 缩放。
* @method setScale
* @param {Number|Vec2} scale - scaleX or scale
* @param {Number} [scaleY=scale]
+ * @example
+ * node.setScale(cc.v2(1, 1));
+ * node.setScale(1, 1);
*/
setScale: function (scale, scaleY) {
if (scale instanceof cc.Vec2) {
@@ -756,25 +871,32 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- *
- * The original point (0,0) is at the left-bottom corner of screen.
- * Usually we use cc.p(x,y) to compose CCPoint object.
- * and Passing two numbers (x,y) is more efficient than passing CCPoint object.
- *
+ * The original point (0,0) is at the left-bottom corner of screen.
+ * Usually we use cc.v2(x,y) to compose CCVec2 object.
+ * and Passing two numbers (x,y) is more efficient than passing CCPoint object.
+ * !#zh
+ * 设置节点在父坐标系中的位置。
+ * 可以通过 2 种方式设置坐标点:
+ * 1.传入 cc.v2(x, y) 类型为 cc.Vec2 的对象。
+ * 2.传入 2 个数值 x 和 y。
* @method setPosition
* @param {Vec2|Number} newPosOrxValue - The position (x,y) of the node in coordinates or the X coordinate for position
* @param {Number} [yValue] - Y coordinate for position
- * @example {@link utils/api/engine/docs/cocos2d/core/utils/node-wrapper/setPosition.js}
+ * @example {@link utils/api/engine/docs/cocos2d/core/utils/base-node/setPosition.js}
*/
setPosition: function (newPosOrxValue, yValue) {
var xValue;
@@ -815,32 +937,50 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- *
- * Anchor point is the point around which all transformations and positioning manipulations take place.
- * It's like a pin in the node where it is "attached" to its parent.
- * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
- * But you can use values higher than (1,1) and lower than (0,0) too.
- * The default anchor point is (0.5,0.5), so it starts at the center of the node.
+ * Anchor point is the point around which all transformations and positioning manipulations take place.
+ * It's like a pin in the node where it is "attached" to its parent.
+ * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
+ * But you can use values higher than (1,1) and lower than (0,0) too.
+ * The default anchor point is (0.5,0.5), so it starts at the center of the node.
+ * !#zh
+ * 获取节点锚点,用百分比表示。
+ * 锚点应用于所有变换和坐标点的操作,它就像在节点上连接其父节点的大头针。
+ * 锚点是标准化的,就像百分比一样。(0,0) 表示左下角,(1,1) 表示右上角。
+ * 但是你可以使用比(1,1)更高的值或者比(0,0)更低的值。
+ * 默认的锚点是(0.5,0.5),因此它开始于节点的中心位置。
+ * 注意:Creator 中的锚点仅用于定位所在的节点,子节点的定位不受影响。
* @method getAnchorPoint
* @return {Vec2} The anchor point of node.
+ * @example
+ * cc.log("Node AnchorPoint: " + node.getAnchorPoint());
*/
getAnchorPoint: function () {
return cc.p(this._anchorPoint);
},
/**
- *
- *
- * anchor point is the point around which all transformations and positioning manipulations take place.
- * It's like a pin in the node where it is "attached" to its parent.
- * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
- * But you can use values higher than (1,1) and lower than (0,0) too.
- * The default anchor point is (0.5,0.5), so it starts at the center of the node.
- *
+ * anchor point is the point around which all transformations and positioning manipulations take place.
+ * It's like a pin in the node where it is "attached" to its parent.
+ * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
+ * But you can use values higher than (1,1) and lower than (0,0) too.
+ * The default anchor point is (0.5,0.5), so it starts at the center of the node.
+ * !#zh
+ * 设置锚点的百分比。
+ * 锚点应用于所有变换和坐标点的操作,它就像在节点上连接其父节点的大头针。
+ * 锚点是标准化的,就像百分比一样。(0,0) 表示左下角,(1,1) 表示右上角。
+ * 但是你可以使用比(1,1)更高的值或者比(0,0)更低的值。
+ * 默认的锚点是(0.5,0.5),因此它开始于节点的中心位置。
+ * 注意:Creator 中的锚点仅用于定位所在的节点,子节点的定位不受影响。
* @method setAnchorPoint
* @param {Vec2|Number} point - The anchor point of node or The x axis anchor of node.
* @param {Number} [y] - The y axis anchor of node.
+ * @example
+ * node.setAnchorPoint(cc.v2(1, 1));
+ * node.setAnchorPoint(1, 1);
*/
setAnchorPoint: function (point, y) {
var locAnchorPoint = this._anchorPoint;
@@ -863,23 +1003,33 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
+ * !#en
* Returns a copy of the anchor point in absolute pixels.
- * you can only read it. If you wish to modify it, use setAnchorPoint
+ * you can only read it. If you wish to modify it, use setAnchorPoint.
+ * !#zh
+ * 返回锚点的绝对像素位置。
+ * 你只能读它。如果您要修改它,使用 setAnchorPoint。
* @see cc.Node#getAnchorPoint
* @method getAnchorPointInPoints
* @return {Vec2} The anchor point in absolute pixels.
+ * @example
+ * cc.log("AnchorPointInPoints: " + node.getAnchorPointInPoints());
*/
getAnchorPointInPoints: function () {
return this._sgNode.getAnchorPointInPoints();
},
/**
- *
+ * !#en
+ * Returns a copy the untransformed size of the node.
* The contentSize remains the same no matter the node is scaled or rotated.
- * All nodes has a size. Layer and Scene has the same size of the screen by default.
+ * !#zh 获取节点自身大小,不受该节点是否被缩放或者旋转的影响。
* @method getContentSize
* @param {Boolean} [ignoreSizeProvider=false] - true if you need to get the original size of the node
* @return {Size} The untransformed size of the node.
+ * @example
+ * cc.log("Content Size: " + node.getContentSize());
*/
getContentSize: function (ignoreSizeProvider) {
if (this._sizeProvider && !ignoreSizeProvider) {
@@ -893,15 +1043,17 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- *
- *
- * The contentSize remains the same no matter the node is scaled or rotated.
- * All nodes has a size. Layer and Scene has the same size of the screen.
- *
+ * The contentSize remains the same no matter the node is scaled or rotated.
+ * All nodes has a size. Layer and Scene has the same size of the screen.
+ * !#zh 设置节点原始大小,不受该节点是否被缩放或者旋转的影响。
* @method setContentSize
* @param {Size|Number} size - The untransformed size of the node or The untransformed size's width of the node.
* @param {Number} [height] - The untransformed size's height of the node.
+ * @example
+ * node.setContentSize(cc.size(100, 100));
+ * node.setContentSize(100, 100);
*/
setContentSize: function (size, height) {
var locContentSize = this._contentSize;
@@ -926,10 +1078,14 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
+ * !#en
* Returns a "local" axis aligned bounding box of the node.
* The returned box is relative only to its parent.
+ * !#zh 返回父节坐标系下的轴向对齐的包围盒。
* @method getBoundingBox
* @return {Rect} The calculated bounding box of the node
+ * @example
+ * var boundingBox = node.getBoundingBox();
*/
getBoundingBox: function () {
var size = this.getContentSize();
@@ -938,8 +1094,11 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Stops all running actions and schedulers
+ * !#en Stops all running actions and schedulers.
+ * !#zh 停止所有正在播放的动作和计时器。
* @method cleanup
+ * @example
+ * node.cleanup();
*/
cleanup: function () {
// actions
@@ -959,10 +1118,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
// composition: GET
/**
- * Returns a child from the container given its tag
+ * !#en Returns a child from the container given its tag.
+ * !#zh 通过标签获取节点的子节点。
* @method getChildByTag
* @param {Number} aTag - An identifier to find the child node.
* @return {Node} a CCNode object whose tag equals to the input parameter
+ * @example
+ * var child = node.getChildByTag(1001);
*/
getChildByTag: function (aTag) {
var children = this._children;
@@ -977,10 +1139,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Returns a child from the container given its uuid
+ * !#en Returns a child from the container given its uuid.
+ * !#zh 通过 uuid 获取节点的子节点。
* @method getChildByUuid
* @param {String} uuid - The uuid to find the child node.
* @return {Node} a Node whose uuid equals to the input parameter
+ * @example
+ * var child = node.getChildByUuid(uuid);
*/
getChildByUuid: function(uuid){
if(!uuid){
@@ -997,10 +1162,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
- * Returns a child from the container given its name
+ * !#en Returns a child from the container given its name.
+ * !#zh 通过名称获取节点的子节点。
* @method getChildByName
* @param {String} name - A name to find the child node.
* @return {Node} a CCNode object whose name equals to the input parameter
+ * @example
+ * var child = node.getChildByName("Test Node");
*/
getChildByName: function(name){
if(!name){
@@ -1018,13 +1186,17 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
// composition: ADD
- /**
+ * !#zh
+ * 添加子节点,并且可以修改该节点的 局部 Z 顺序和标签。
* @method addChild
* @param {Node} child - A child node
- * @param {Number} [localZOrder=] - Z order for drawing priority. Please refer to setZOrder(int)
- * @param {Number|String} [tag=] - An integer or a name to identify the node easily. Please refer to setTag(int) and setName(string)
+ * @param {Number} [localZOrder] - Z order for drawing priority. Please refer to setZOrder(int)
+ * @param {Number|String} [tag] - An integer or a name to identify the node easily. Please refer to setTag(int) and setName(string)
+ * @example
+ * node.addChild(newNode, 1, 1001);
*/
addChild: function (child, localZOrder, tag) {
localZOrder = localZOrder === undefined ? child._localZOrder : localZOrder;
@@ -1062,12 +1234,20 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
// composition: REMOVE
/**
+ * !#en
* Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
* If the cleanup parameter is not passed, it will force a cleanup.
* If the node orphan, then nothing happens.
+ * !#zh
+ * 从父节点中删除一个节点。cleanup 参数为 true,那么在这个节点上所有的动作和回调都会被删除,反之则不会。
+ * 如果不传入 cleanup 参数,默认是 true 的。
+ * 如果这个节点是一个孤节点,那么什么都不会发生。
* @method removeFromParent
* @param {Boolean} [cleanup=true] - true if all actions and callbacks on this node should be removed, false otherwise.
* @see cc.Node#removeFromParentAndCleanup
+ * @example
+ * node.removeFromParent();
+ * node.removeFromParent(false);
*/
removeFromParent: function (cleanup) {
if (this._parent) {
@@ -1077,14 +1257,22 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
}
},
- /**
"remove" logic MUST only be on this method
+ * "remove" logic MUST only be on this method
* If a class wants to extend the 'removeChild' behavior it only needs
- * to override this method
Returns the x axis position of the node in cocos2d coordinates.
+ * !#en Returns the x axis position of the node in cocos2d coordinates. + * !#zh 获取节点 X 轴坐标。 * @method getPositionX - * @param {Number} x - The new position in x axis + * @return {Number} x - The new position in x axis + * @example + * var posX = node.getPositionX(); */ /** - *Sets the x axis position of the node in cocos2d coordinates.
+ * !#en Sets the x axis position of the node in cocos2d coordinates. + * !#zh 设置节点 X 轴坐标。 * @method setPositionX - * @return {Number} + * @param {Number} x + * @example + * node.setPositionX(1); */ /** - *Returns the y axis position of the node in cocos2d coordinates.
+ * !#en Returns the y axis position of the node in cocos2d coordinates. + * !#zh 获取节点 Y 轴坐标。 * @method getPositionY * @return {Number} + * @example + * var posY = node.getPositionY(); */ /** - *Sets the y axis position of the node in cocos2d coordinates.
+ * !#en Sets the y axis position of the node in cocos2d coordinates. + * !#zh 设置节点 Y 轴坐标。 * @method setPositionY * @param {Number} y - The new position in y axis + * @example + * node.setPositionY(100); */ /** - * Returns the local Z order of this node. + * !#en Returns the local Z order of this node. + * !#zh 获取节点局部 Z 轴顺序。 * @method getLocalZOrder * @returns {Number} The local (relative to its siblings) Z order. + * @example + * var localZorder = node.getLocalZOrder(); */ /** - * LocalZOrder is the 'key' used to sort the node relative to its siblings.
+ * !#en
+ * LocalZOrder is the 'key' used to sort the node relative to its siblings.
*
* The Node's parent will sort all its children based ont the LocalZOrder value.
* If two nodes have the same LocalZOrder, then the node that was added first to the children's array
* will be in front of the other node in the array.
- *
- * Also, the Scene Graph is traversed using the "In-Order" tree traversal algorithm ( http://en.wikipedia.org/wiki/Tree_traversal#In-order )
- *
- * And Nodes that have LocalZOder values smaller than 0 are the "left" subtree
- * While Nodes with LocalZOder greater than 0 are the "right" subtree.
- * Sets whether the anchor point will be ignored when you position this node.
- * When anchor point ignored, position will be calculated based on the origin point (0, 0) in parent's coordinates.
- * This is an internal method, only used by CCLayer and CCScene. Don't call it outside framework.
- * The default value is false, while in CCLayer and CCScene are true
- *