diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js
index dc5a533e5b..416e087a12 100644
--- a/cocos2d/core/CCNode.js
+++ b/cocos2d/core/CCNode.js
@@ -33,21 +33,24 @@ var DontDestroy = Flags.DontDestroy;
//var RegisteredInEditor = Flags.RegisteredInEditor;
/**
- * The event type supported by Node
+ * !#en The event type supported by Node
+ * !#zh Node 支持的事件类型
* @enum Node.EventType
* @static
* @namespace Node
*/
var EventType = cc.Enum({
/**
- * The event type for touch start event, you can use its value directly: 'touchstart'
+ * !#en The event type for touch start event, you can use its value directly: 'touchstart'
+ * !#zh 当手指触摸到屏幕时。
* @property TOUCH_START
* @type {String}
* @static
*/
TOUCH_START: 'touchstart',
/**
- * The event type for touch move event, you can use its value directly: 'touchmove'
+ * !#en The event type for touch move event, you can use its value directly: 'touchmove'
+ * !#zh 当手指在屏幕上目标节点区域内移动时。
* @property TOUCH_MOVE
* @type {String}
* @value 1
@@ -55,14 +58,16 @@ var EventType = cc.Enum({
*/
TOUCH_MOVE: 'touchmove',
/**
- * The event type for touch end event, you can use its value directly: 'touchend'
+ * !#en The event type for touch end event, you can use its value directly: 'touchend'
+ * !#zh 当手指在目标节点区域内离开屏幕时。
* @property TOUCH_END
* @type {String}
* @static
*/
TOUCH_END: 'touchend',
/**
- * The event type for touch end event, you can use its value directly: 'touchcancel'
+ * !#en The event type for touch end event, you can use its value directly: 'touchcancel'
+ * !#zh 当手指在目标节点区域外离开屏幕时。
* @property TOUCH_CANCEL
* @type {String}
* @static
@@ -70,42 +75,48 @@ var EventType = cc.Enum({
TOUCH_CANCEL: 'touchcancel',
/**
- * The event type for mouse down events, you can use its value directly: 'mousedown'
+ * !#en The event type for mouse down events, you can use its value directly: 'mousedown'
+ * !#zh 当鼠标按下时触发一次。
* @property MOUSE_DOWN
* @type {String}
* @static
*/
MOUSE_DOWN: 'mousedown',
/**
- * The event type for mouse move events, you can use its value directly: 'mousemove'
+ * !#en The event type for mouse move events, you can use its value directly: 'mousemove'
+ * !#zh 当鼠标在目标节点在目标节点区域中移动时,不论是否按下。
* @property MOUSE_MOVE
* @type {String}
* @static
*/
MOUSE_MOVE: 'mousemove',
/**
- * The event type for mouse enter target events, you can use its value directly: 'mouseenter'
+ * !#en The event type for mouse enter target events, you can use its value directly: 'mouseenter'
+ * !#zh 当鼠标移入目标节点区域时,不论是否按下。
* @property MOUSE_ENTER
* @type {String}
* @static
*/
MOUSE_ENTER: 'mouseenter',
/**
- * The event type for mouse leave target events, you can use its value directly: 'mouseleave'
+ * !#en The event type for mouse leave target events, you can use its value directly: 'mouseleave'
+ * !#zh 当鼠标移出目标节点区域时,不论是否按下。
* @property MOUSE_LEAVE
* @type {String}
* @static
*/
MOUSE_LEAVE: 'mouseleave',
/**
- * The event type for mouse up events, you can use its value directly: 'mouseup'
+ * !#en The event type for mouse up events, you can use its value directly: 'mouseup'
+ * !#zh 当鼠标从按下状态松开时触发一次。
* @property MOUSE_UP
* @type {String}
* @static
*/
MOUSE_UP: 'mouseup',
/**
- * The event type for mouse wheel events, you can use its value directly: 'mousewheel'
+ * !#en The event type for mouse wheel events, you can use its value directly: 'mousewheel'
+ * !#zh 当鼠标滚轮滚动时。
* @property MOUSE_WHEEL
* @type {String}
* @static
diff --git a/cocos2d/core/event-manager/CCEventListener.js b/cocos2d/core/event-manager/CCEventListener.js
index 18a4f2ecb4..de0a27baa8 100644
--- a/cocos2d/core/event-manager/CCEventListener.js
+++ b/cocos2d/core/event-manager/CCEventListener.js
@@ -23,27 +23,36 @@
THE SOFTWARE.
****************************************************************************/
/**
+ * !#en
*
* The base class of event listener.
* If you need custom listener which with different callback, you need to inherit this class.
* For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard,
* EventListenerTouchOneByOne, EventListenerCustom.
*
+ *
+ * !#zh
+ * 封装用户的事件处理逻辑。
+ * 注意:这是一个抽象类,开发者不应该直接实例化这个类,请参考 cc.EventListener.create。
+ *
* @class EventListener
+ * @param {Number} type
+ * @param {Number} listenerID
+ * @param {Number} callback
*/
cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
- _onEvent: null, // Event callback function
- _type: 0, // Event listener type
- _listenerID: null, // Event listener ID
- _registered: false, // Whether the listener has been added to dispatcher.
+ _onEvent: null, // Event callback function
+ _type: 0, // Event listener type
+ _listenerID: null, // Event listener ID
+ _registered: false, // Whether the listener has been added to dispatcher.
- _fixedPriority: 0, // The higher the number, the higher the priority, 0 is for scene graph base priority.
- _node: null, // scene graph based priority
+ _fixedPriority: 0, // The higher the number, the higher the priority, 0 is for scene graph base priority.
+ _node: null, // scene graph based priority
_target: null,
- _paused: true, // Whether the listener is paused
- _isEnabled: true, // Whether the listener is enabled
+ _paused: true, // Whether the listener is paused
+ _isEnabled: true, // Whether the listener is enabled
- /**
+ /*
* Initializes event with type and callback function.
* @param {Number} type
* @param {String} listenerID
@@ -55,7 +64,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
this._listenerID = listenerID || "";
},
- /**
+ /*
*
* Sets paused state for the listener
* The paused state is only used for scene graph priority listeners.
@@ -72,7 +81,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
this._paused = paused;
},
- /**
+ /*
* Checks whether the listener is paused.
* @returns {Boolean}
* @private
@@ -81,7 +90,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
return this._paused;
},
- /**
+ /*
* Marks the listener was registered by EventDispatcher.
* @param {Boolean} registered
* @private
@@ -90,7 +99,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
this._registered = registered;
},
- /**
+ /*
* Checks whether the listener was registered by EventDispatcher
* @returns {Boolean}
* @private
@@ -99,7 +108,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
return this._registered;
},
- /**
+ /*
* Gets the type of this listener
* @note It's different from `EventType`, e.g. TouchEvent has two kinds of event listeners - EventListenerOneByOne, EventListenerAllAtOnce
* @returns {Number}
@@ -109,7 +118,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
return this._type;
},
- /**
+ /*
* Gets the listener ID of this listener
* When event is being dispatched, listener ID is used as key for searching listeners according to event type.
* @returns {String}
@@ -119,7 +128,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
return this._listenerID;
},
- /**
+ /*
* Sets the fixed priority for this listener
* @note This method is only used for `fixed priority listeners`, it needs to access a non-zero value. 0 is reserved for scene graph priority listeners
* @param {Number} fixedPriority
@@ -129,7 +138,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
this._fixedPriority = fixedPriority;
},
- /**
+ /*
* Gets the fixed priority of this listener
* @returns {Number} 0 if it's a scene graph priority listener, non-zero for fixed priority listener
* @private
@@ -138,7 +147,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
return this._fixedPriority;
},
- /**
+ /*
* Sets scene graph priority for this listener
* @param {_ccsg.Node|Node} node
* @private
@@ -148,7 +157,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
this._node = node;
},
- /**
+ /*
* Gets scene graph priority of this listener
* @returns {_ccsg.Node|cc.Node} if it's a fixed priority listener, non-null for scene graph priority listener
* @private
@@ -158,7 +167,9 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
},
/**
- * Checks whether the listener is available.
+ * !#en Checks whether the listener is available.
+ * !#zh 检测监听器是否有效
+ * @method checkAvailable
* @returns {Boolean}
*/
checkAvailable: function () {
@@ -166,7 +177,9 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
},
/**
- * Clones the listener, its subclasses have to override this method.
+ * !#en Clones the listener, its subclasses have to override this method.
+ * !#zh 克隆监听器,它的子类必须重写此方法。
+ * @method clone
* @returns {EventListener}
*/
clone: function () {
@@ -174,26 +187,30 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
},
/**
- * Enables or disables the listener
+ * !#en Enables or disables the listener
+ * !#zh 启用或禁用监听器。
+ * @method setEnabled
+ * @param {Boolean} enabled
* @note Only listeners with `enabled` state will be able to receive events.
* When an listener was initialized, it's enabled by default.
* An event listener can receive events when it is enabled and is not paused.
* paused state is always false when it is a fixed priority listener.
- * @param {Boolean} enabled
*/
setEnabled: function(enabled){
this._isEnabled = enabled;
},
/**
- * Checks whether the listener is enabled
+ * !#en Checks whether the listener is enabled
+ * !#zh 检查监听器是否可用。
+ * @method isEnabled
* @returns {Boolean}
*/
isEnabled: function(){
return this._isEnabled;
},
- /**
+ /*
*
Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB,
* and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB.
* This is a hack, and should be removed once JSB fixes the retain/release bug
@@ -209,7 +226,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
*/
retain:function () {
},
- /**
+ /*
*
Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB,
* and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB.
* This is a hack, and should be removed once JSB fixes the retain/release bug
@@ -229,49 +246,58 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{
// event listener type
/**
- * The type code of unknown event listener.
+ * !#en The type code of unknown event listener.
+ * !#zh 未知的事件监听器类型。
+ * @property EventListener.UNKNOWN
* @constant
* @type {Number}
*/
cc.EventListener.UNKNOWN = 0;
-/**
- * The type code of one by one touch event listener.
+/*
+ * !#en The type code of one by one touch event listener.
+ * !#zh 触摸事件监听器类型,触点会一个一个得分开被派发。
* @constant
* @type {Number}
*/
cc.EventListener.TOUCH_ONE_BY_ONE = 1;
-/**
- * The type code of all at once touch event listener.
+/*
+ * !#en The type code of all at once touch event listener.
+ * !#zh 触摸事件监听器类型,触点会被一次性全部派发。
* @constant
* @type {Number}
*/
cc.EventListener.TOUCH_ALL_AT_ONCE = 2;
/**
- * The type code of keyboard event listener.
- * @constant
+ * !#en The type code of keyboard event listener.
+ * !#zh 键盘事件监听器类型。
+ * @constant EventListener.KEYBOARD
* @type {Number}
*/
cc.EventListener.KEYBOARD = 3;
-/**
- * The type code of mouse event listener.
+/*
+ * !#en The type code of mouse event listener.
+ * !#zh 鼠标事件监听器类型。
* @constant
* @type {Number}
*/
cc.EventListener.MOUSE = 4;
/**
- * The type code of focus event listener.
- * @constant
+ * !#en The type code of focus event listener.
+ * !#zh 加速器事件监听器类型。
+ * @constant EventListener.ACCELERATION
* @type {Number}
*/
cc.EventListener.ACCELERATION = 6;
-/**
- * The type code of Focus change event listener.
+/*
+ * !#en The type code of Focus change event listener.
+ * !#zh 焦点事件监听器类型。
* @constant
* @type {Number}
*/
cc.EventListener.FOCUS = 7;
-/**
- * The type code of custom event listener.
+/*
+ * !#en The type code of custom event listener.
+ * !#zh 自定义事件监听器类型。
* @constant
* @type {Number}
*/
@@ -423,12 +449,16 @@ cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({
cc._EventListenerTouchAllAtOnce.LISTENER_ID = "__cc_touch_all_at_once";
/**
- * Create a EventListener object by json object
+ * !#en
+ * Create a EventListener object with configuration including the event type, handlers and other parameters.
+ * In handlers, this refer to the event listener object itself.
+ * You can also pass custom parameters in the configuration object,
+ * all custom parameters will be polyfilled into the event listener object and can be accessed in handlers.
+ * !#zh 通过指定不同的 Event 对象来设置想要创建的事件监听器。
* @method create
* @static
* @param {Object} argObj a json object
* @returns {EventListener}
- * todo: It should be the direct use new
* @example {@link utils/api/engine/docs/cocos2d/core/event-manager/CCEventListener/create.js}
*/
cc.EventListener.create = function(argObj){
diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js
index 0a214f5c6d..ea7146ae68 100644
--- a/cocos2d/core/event-manager/CCEventManager.js
+++ b/cocos2d/core/event-manager/CCEventManager.js
@@ -89,13 +89,20 @@ var __getListenerID = function (event) {
};
/**
+ * !#en
*
* cc.eventManager is a singleton object which manages event listener subscriptions and event dispatching.
*
* The EventListener list is managed in such way so that event listeners can be added and removed
* while events are being dispatched.
*
+ * !#zh
+ * 事件管理器,它主要管理事件监听器注册和派发系统事件。
+ * 原始设计中,它支持鼠标,触摸,键盘,陀螺仪和自定义事件。
+ * 在 Creator 的设计中,鼠标,触摸和自定义事件的监听和派发请参考 http://cocos.com/docs/creator/scripting/events.html。
+ *
* @class eventManager
+ * @example {@link utils/api/engine/docs/cocos2d/core/event-manager/CCEventManager/addListener.js}
*/
cc.eventManager = {
//Priority dirty flag
@@ -130,10 +137,11 @@ cc.eventManager = {
},
/**
- * Pauses all listeners which are associated the specified target.
+ * !#en Pauses all listeners which are associated the specified target.
+ * !#zh 暂停传入的 node 相关的所有监听器的事件响应。
* @method pauseTarget
* @param {Node} node
- * @param {Boolean} [recursive=false]
+ * @param {Boolean} recursive
*/
pauseTarget: function (node, recursive) {
var listeners = this._nodeListenersMap[node.__instanceId], i, len;
@@ -149,10 +157,11 @@ cc.eventManager = {
},
/**
- * Resumes all listeners which are associated the specified target.
+ * !#en Resumes all listeners which are associated the specified target.
+ * !#zh 恢复传入的 node 相关的所有监听器的事件响应。
* @method resumeTarget
* @param {Node} node
- * @param {Boolean} [recursive=false]
+ * @param {Boolean} recursive
*/
resumeTarget: function (node, recursive) {
var listeners = this._nodeListenersMap[node.__instanceId], i, len;
@@ -638,11 +647,19 @@ cc.eventManager = {
},
/**
+ * !#en
*
- * Adds a event listener for a specified event.
- * if the parameter "nodeOrPriority" is a node, it means to add a event listener for a specified event with the priority of scene graph.
- * if the parameter "nodeOrPriority" is a Number, it means to add a event listener for a specified event with the fixed priority.
+ * Adds a event listener for a specified event.
+ * if the parameter "nodeOrPriority" is a node,
+ * it means to add a event listener for a specified event with the priority of scene graph.
+ * if the parameter "nodeOrPriority" is a Number,
+ * it means to add a event listener for a specified event with the fixed priority.
*
+ * !#zh
+ * 将事件监听器添加到事件管理器中。
+ * 如果参数 “nodeOrPriority” 是节点,优先级由 node 的渲染顺序决定,显示在上层的节点将优先收到事件。
+ * 如果参数 “nodeOrPriority” 是数字,优先级则固定为该参数的数值,数字越小,优先级越高。
+ *
* @method addListener
* @param {EventListener|Object} listener - The listener of a specified event or a object of some event parameters.
* @param {Node|Number} nodeOrPriority - The priority of the listener is based on the draw order of this node or fixedPriority The fixed priority of the listener.
@@ -688,8 +705,9 @@ cc.eventManager = {
return listener;
},
- /**
- * Adds a Custom event listener. It will use a fixed priority of 1.
+ /*
+ * !#en Adds a Custom event listener. It will use a fixed priority of 1.
+ * !#zh 向事件管理器添加一个自定义事件监听器。
* @method addCustomListener
* @param {String} eventName
* @param {Function} callback
@@ -702,9 +720,11 @@ cc.eventManager = {
},
/**
- * Remove a listener.
+ * !#en Remove a listener.
+ * !#zh 移除一个已添加的监听器。
* @method removeListener
* @param {EventListener} listener - an event listener or a registered node target
+ * @example {@link utils/api/engine/docs/cocos2d/core/event-manager/CCEventManager/removeListener.js}
*/
removeListener: function (listener) {
if (listener == null)
@@ -790,10 +810,22 @@ cc.eventManager = {
},
/**
- * Removes all listeners with the same event listener type or removes all listeners of a node
+ * !#en Removes all listeners with the same event listener type or removes all listeners of a node.
+ * !#zh
+ * 移除注册到 eventManager 中指定类型的所有事件监听器。
+ * 1. 如果传入的第一个参数类型是 Node,那么事件管理器将移除与该对象相关的所有事件监听器。
+ * (如果第二参数 recursive 是 true 的话,就会连同该对象的子控件上所有的事件监听器也一并移除)
+ * 2. 如果传入的第一个参数类型是 Number(该类型 EventListener 中定义的事件类型),
+ * 那么事件管理器将移除该类型的所有事件监听器。
+ *
+ * 下列是目前存在监听器类型:
+ * cc.EventListener.UNKNOWN
+ * cc.EventListener.KEYBOARD
+ * cc.EventListener.ACCELERATION,
+ *
* @method removeListeners
* @param {Number|Node} listenerType - listenerType or a node
- * @param {Boolean} [recursive=false]
+ * @param {Boolean} recursive
*/
removeListeners: function (listenerType, recursive) {
var i, _t = this;
@@ -847,8 +879,9 @@ cc.eventManager = {
}
},
- /**
- * Removes all custom listeners with the same event name
+ /*
+ * !#en Removes all custom listeners with the same event name.
+ * !#zh 移除同一事件名的自定义事件监听器。
* @method removeCustomListeners
* @param {String} customEventName
*/
@@ -857,7 +890,8 @@ cc.eventManager = {
},
/**
- * Removes all listeners
+ * !#en Removes all listeners
+ * !#zh 移除所有事件监听器。
* @method removeAllListeners
*/
removeAllListeners: function () {
@@ -869,7 +903,8 @@ cc.eventManager = {
},
/**
- * Sets listener's priority with fixed value.
+ * !#en Sets listener's priority with fixed value.
+ * !#zh 设置 FixedPriority 类型监听器的优先级。
* @method setPriority
* @param {EventListener} listener
* @param {Number} fixedPriority
@@ -898,7 +933,8 @@ cc.eventManager = {
},
/**
- * Whether to enable dispatching events
+ * !#en Whether to enable dispatching events
+ * !#zh 启用或禁用事件管理器,禁用后不会分发任何事件。
* @method setEnabled
* @param {Boolean} enabled
*/
@@ -907,7 +943,8 @@ cc.eventManager = {
},
/**
- * Checks whether dispatching events is enabled
+ * !#en Checks whether dispatching events is enabled
+ * !#zh 检测事件管理器是否启用。
* @method isEnabled
* @returns {Boolean}
*/
@@ -915,8 +952,9 @@ cc.eventManager = {
return this._isEnabled;
},
- /**
- * Dispatches the event, also removes all EventListeners marked for deletion from the event dispatcher list.
+ /*
+ * !#en Dispatches the event, also removes all EventListeners marked for deletion from the event dispatcher list.
+ * !#zh 分发事件。
* @method dispatchEvent
* @param {Event} event
*/
@@ -950,8 +988,9 @@ cc.eventManager = {
return event.isStopped();
},
- /**
- * Dispatches a Custom Event with a event name an optional user data
+ /*
+ * !#en Dispatches a Custom Event with a event name an optional user data
+ * !#zh 分发自定义事件。
* @method dispatchCustomEvent
* @param {String} eventName
* @param {*} optionalUserData
diff --git a/cocos2d/core/event-manager/CCSystemEvent.js b/cocos2d/core/event-manager/CCSystemEvent.js
index 49862b119f..f2dd6198f3 100644
--- a/cocos2d/core/event-manager/CCSystemEvent.js
+++ b/cocos2d/core/event-manager/CCSystemEvent.js
@@ -28,32 +28,30 @@ var JS = cc.js;
var Event = cc.Event;
/**
- * The type code of Touch event.
+ * !#en The type code of Touch event.
+ * !#zh 触摸事件类型
* @constant
* @type {String}
*/
cc.Event.TOUCH = 'touch';
/**
- * The type code of Mouse event.
+ * !#en The type code of Mouse event.
+ * !#zh 鼠标事件类型
* @constant
* @type {String}
*/
cc.Event.MOUSE = 'mouse';
/**
- * The type code of UI focus event.
- * @constant
- * @type {String}
- */
-cc.Event.FOCUS = 'focus';
-/**
- * The type code of Keyboard event.
+ * !#en The type code of Keyboard event.
+ * !#zh 键盘事件类型
* @constant
* @memberof cc.Event
* @type {String}
*/
cc.Event.KEYBOARD = 'keyboard';
/**
- * The type code of Acceleration event.
+ * !#en The type code of Acceleration event.
+ * !#zh 加速器事件类型
* @constant
* @memberof cc.Event
* @type {String}
@@ -61,7 +59,8 @@ cc.Event.KEYBOARD = 'keyboard';
cc.Event.ACCELERATION = 'acceleration';
/**
- * The mouse event
+ * !#en The mouse event
+ * !#zh 鼠标事件类型
* @class Event.EventMouse
* @constructor
* @extends Event
@@ -83,7 +82,8 @@ var EventMouse = function (eventType, bubbles) {
JS.extend(EventMouse, cc.Event);
JS.mixin(EventMouse.prototype, {
/**
- * Sets scroll data.
+ * !#en Sets scroll data.
+ * !#zh 设置鼠标的滚动数据。
* @method setScrollData
* @param {Number} scrollX
* @param {Number} scrollY
@@ -94,7 +94,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns the x axis scroll value.
+ * !#en Returns the x axis scroll value.
+ * !#zh 获取鼠标滚动的X轴距离,只有滚动时才有效。
* @method getScrollX
* @returns {Number}
*/
@@ -103,7 +104,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns the y axis scroll value.
+ * !#en Returns the y axis scroll value.
+ * !#zh 获取滚轮滚动的 Y 轴距离,只有滚动时才有效。
* @method getScrollY
* @returns {Number}
*/
@@ -112,7 +114,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Sets cursor location.
+ * !#en Sets cursor location.
+ * !#zh 设置当前鼠标位置。
* @method setLocation
* @param {Number} x
* @param {Number} y
@@ -123,7 +126,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns cursor location.
+ * !#en Returns cursor location.
+ * !#zh 获取鼠标位置对象,对象包含 x 和 y 属性。
* @method getLocation
* @return {Vec2} location
*/
@@ -132,7 +136,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns the current cursor location in screen coordinates.
+ * !#en Returns the current cursor location in screen coordinates.
+ * !#zh 获取当前事件在游戏窗口内的坐标位置对象,对象包含 x 和 y 属性。
* @method getLocationInView
* @return {Vec2}
*/
@@ -146,7 +151,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns the previous touch location.
+ * !#en Returns the previous touch location.
+ * !#zh 获取鼠标点击在上一次事件时的位置对象,对象包含 x 和 y 属性。
* @method getPreviousLocation
* @return {Vec2}
*/
@@ -155,7 +161,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns the delta distance from the previous location to current location.
+ * !#en Returns the delta distance from the previous location to current location.
+ * !#zh 获取鼠标距离上一次事件移动的距离对象,对象包含 x 和 y 属性。
* @method getDelta
* @return {Vec2}
*/
@@ -164,8 +171,9 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns the X axis delta distance from the previous location to current location.
- * @method getDeltaX
+ * !#en Returns the X axis delta distance from the previous location to current location.
+ * !#zh 获取鼠标距离上一次事件移动的 X 轴距离。
+ * @method getDeltaX。
* @return {Number}
*/
getDeltaX: function () {
@@ -173,7 +181,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns the Y axis delta distance from the previous location to current location.
+ * !#en Returns the Y axis delta distance from the previous location to current location.
+ * !#zh 获取鼠标距离上一次事件移动的 Y 轴距离。
* @method getDeltaY
* @return {Number}
*/
@@ -182,7 +191,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Sets mouse button.
+ * !#en Sets mouse button.
+ * !#zh 设置鼠标按键。
* @method setButton
* @param {Number} button
*/
@@ -191,7 +201,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns mouse button.
+ * !#en Returns mouse button.
+ * !#zh 获取鼠标按键。
* @method getButton
* @returns {Number}
*/
@@ -200,7 +211,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns location X axis data.
+ * !#en Returns location X axis data.
+ * !#zh 获取鼠标当前位置 X 轴。
* @method getLocationX
* @returns {Number}
*/
@@ -209,7 +221,8 @@ JS.mixin(EventMouse.prototype, {
},
/**
- * Returns location Y axis data.
+ * !#en Returns location Y axis data.
+ * !#zh 获取鼠标当前位置 Y 轴。
* @method getLocationY
* @returns {Number}
*/
@@ -220,99 +233,113 @@ JS.mixin(EventMouse.prototype, {
//Inner event types of MouseEvent
/**
- * The none event code of mouse event.
+ * !#en The none event code of mouse event.
+ * !#zh 无。
* @constant
* @type {Number}
*/
EventMouse.NONE = 0;
/**
- * The event type code of mouse down event.
+ * !#en The event type code of mouse down event.
+ * !#zh 鼠标按下事件。
* @constant
* @type {Number}
*/
EventMouse.DOWN = 1;
/**
- * The event type code of mouse up event.
+ * !#en The event type code of mouse up event.
+ * !#zh 鼠标按下后释放事件。
* @constant
* @type {Number}
*/
EventMouse.UP = 2;
/**
- * The event type code of mouse move event.
+ * !#en The event type code of mouse move event.
+ * !#zh 鼠标移动事件。
* @constant
* @type {Number}
*/
EventMouse.MOVE = 3;
/**
- * The event type code of mouse scroll event.
+ * !#en The event type code of mouse scroll event.
+ * !#zh 鼠标滚轮事件。
* @constant
* @type {Number}
*/
EventMouse.SCROLL = 4;
/**
- * The tag of Mouse left button
+ * !#en The tag of Mouse left button.
+ * !#zh 鼠标左键的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_LEFT = 0;
/**
- * The tag of Mouse right button (The right button number is 2 on browser)
+ * !#en The tag of Mouse right button (The right button number is 2 on browser).
+ * !#zh 鼠标右键的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_RIGHT = 2;
/**
- * The tag of Mouse middle button (The right button number is 1 on browser)
+ * !#en The tag of Mouse middle button (The right button number is 1 on browser).
+ * !#zh 鼠标中键的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_MIDDLE = 1;
/**
- * The tag of Mouse button 4
+ * !#en The tag of Mouse button 4.
+ * !#zh 鼠标按键 4 的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_4 = 3;
/**
- * The tag of Mouse button 5
+ * !#en The tag of Mouse button 5.
+ * !#zh 鼠标按键 5 的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_5 = 4;
/**
- * The tag of Mouse button 6
+ * !#en The tag of Mouse button 6.
+ * !#zh 鼠标按键 6 的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_6 = 5;
/**
- * The tag of Mouse button 7
+ * !#en The tag of Mouse button 7.
+ * !#zh 鼠标按键 7 的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_7 = 6;
/**
- * The tag of Mouse button 8
+ * !#en The tag of Mouse button 8.
+ * !#zh 鼠标按键 8 的标签。
* @constant
* @type {Number}
*/
EventMouse.BUTTON_8 = 7;
/**
- * The touch event
+ * !#en The touch event
+ * !#zh 触摸事件
* @class Event.EventTouch
* @constructor
* @extends Event
- * @param {Array} [touchArr=[]] - The array of the touches
- * @param {Boolean} [bubbles=false] - A boolean indicating whether the event bubbles up through the tree or not
+ * @param {Array} touchArr - The array of the touches
+ * @param {Boolean} bubbles - A boolean indicating whether the event bubbles up through the tree or not
*/
var EventTouch = function (touchArr, bubbles) {
cc.Event.call(this, cc.Event.TOUCH, bubbles);
@@ -324,7 +351,8 @@ var EventTouch = function (touchArr, bubbles) {
JS.extend(EventTouch, cc.Event);
JS.mixin(EventTouch.prototype, {
/**
- * Returns event code.
+ * !#en Returns event code.
+ * !#zh 获取事件类型。
* @method getEventCode
* @returns {Number}
*/
@@ -333,7 +361,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns touches of event.
+ * !#en Returns touches of event.
+ * !#zh 获取触摸点的列表。
* @method getTouches
* @returns {Array}
*/
@@ -350,7 +379,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Sets touch location.
+ * !#en Sets touch location.
+ * !#zh 设置当前触点位置
* @method setLocation
* @param {Number} x
* @param {Number} y
@@ -360,7 +390,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns touch location.
+ * !#en Returns touch location.
+ * !#zh 获取触点位置。
* @method getLocation
* @return {Vec2} location
*/
@@ -369,7 +400,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns the current touch location in screen coordinates.
+ * !#en Returns the current touch location in screen coordinates.
+ * !#zh 获取当前触点在游戏窗口中的位置。
* @method getLocationInView
* @return {Vec2}
*/
@@ -378,7 +410,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns the previous touch location.
+ * !#en Returns the previous touch location.
+ * !#zh 获取触点在上一次事件时的位置对象,对象包含 x 和 y 属性。
* @method getPreviousLocation
* @return {Vec2}
*/
@@ -387,7 +420,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns the start touch location.
+ * !#en Returns the start touch location.
+ * !#zh 获获取触点落下时的位置对象,对象包含 x 和 y 属性。
* @method getStartLocation
* @returns {Vec2}
*/
@@ -396,7 +430,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns the id of cc.Touch.
+ * !#en Returns the id of cc.Touch.
+ * !#zh 触点的标识 ID,可以用来在多点触摸中跟踪触点。
* @method getID
* @return {Number}
*/
@@ -405,7 +440,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns the delta distance from the previous location to current location.
+ * !#en Returns the delta distance from the previous location to current location.
+ * !#zh 获取触点距离上一次事件移动的距离对象,对象包含 x 和 y 属性。
* @method getDelta
* @return {Vec2}
*/
@@ -414,7 +450,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns the X axis delta distance from the previous location to current location.
+ * !#en Returns the X axis delta distance from the previous location to current location.
+ * !#zh 获取触点距离上一次事件移动的 x 轴距离。
* @method getDeltaX
* @return {Number}
*/
@@ -423,7 +460,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns the Y axis delta distance from the previous location to current location.
+ * !#en Returns the Y axis delta distance from the previous location to current location.
+ * !#zh 获取触点距离上一次事件移动的 y 轴距离。
* @method getDeltaY
* @return {Number}
*/
@@ -432,7 +470,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns location X axis data.
+ * !#en Returns location X axis data.
+ * !#zh 获取当前触点 X 轴位置。
* @method getLocationX
* @returns {Number}
*/
@@ -441,7 +480,8 @@ JS.mixin(EventTouch.prototype, {
},
/**
- * Returns location Y axis data.
+ * !#en Returns location Y axis data.
+ * !#zh 获取当前触点 Y 轴位置。
* @method getLocationY
* @returns {Number}
*/
@@ -451,60 +491,50 @@ JS.mixin(EventTouch.prototype, {
});
/**
- * The maximum touch numbers
+ * !#en The maximum touch numbers
+ * !#zh 最大触摸数量。
* @constant
* @type {Number}
*/
EventTouch.MAX_TOUCHES = 5;
/**
- * The event type code of touch began event.
+ * !#en The event type code of touch began event.
+ * !#zh 开始触摸事件
* @constant
* @type {Number}
*/
EventTouch.BEGAN = 0;
/**
- * The event type code of touch moved event.
+ * !#en The event type code of touch moved event.
+ * !#zh 触摸后移动事件
* @constant
* @type {Number}
*/
EventTouch.MOVED = 1;
/**
- * The event type code of touch ended event.
+ * !#en The event type code of touch ended event.
+ * !#zh 结束触摸事件
* @constant
* @type {Number}
*/
EventTouch.ENDED = 2;
/**
- * The event type code of touch cancelled event.
+ * !#en The event type code of touch cancelled event.
+ * !#zh 取消触摸事件
* @constant
* @type {Number}
*/
EventTouch.CANCELED = 3;
/**
- * Focus change event for UI widget
- * @class Event.EventFocus
- * @constructor
- * @extends Event
- * @param {Widget} widgetLoseFocus
- * @param {Widget} widgetGetFocus
- * @param {Boolean} [bubbles=false] - A boolean indicating whether the event bubbles up through the tree or not
- */
-EventFocus = function (widgetGetFocus, widgetLoseFocus, bubbles) {
- cc.Event.call(this, cc.Event.FOCUS, bubbles);
- this._widgetGetFocus = widgetGetFocus;
- this._widgetLoseFocus = widgetLoseFocus;
-};
-JS.extend(EventFocus, cc.Event);
-
-/**
- * The acceleration event
+ * !#en The acceleration event
+ * !#zh 加速度事件
* @class Event.EventAcceleration
* @extends Event
* @constructor
* @param {Object} acc - The acceleration
- * @param {Boolean} [bubbles=false] - A boolean indicating whether the event bubbles up through the tree or not
+ * @param {Boolean} bubbles - A boolean indicating whether the event bubbles up through the tree or not
*/
EventAcceleration = function (acc, bubbles) {
cc.Event.call(this, Event.ACCELERATION, bubbles);
@@ -513,13 +543,14 @@ EventAcceleration = function (acc, bubbles) {
JS.extend(EventAcceleration, cc.Event);
/**
- * The keyboard event
+ * !#en The keyboard event
+ * !#zh 键盘事件
* @class Event.EventKeyboard
* @extends Event
* @constructor
* @param {Number} keyCode - The key code of which triggered this event
* @param {Boolean} isPressed - A boolean indicating whether the key have been pressed
- * @param {Boolean} [bubbles=false] - A boolean indicating whether the event bubbles up through the tree or not
+ * @param {Boolean} bubbles - A boolean indicating whether the event bubbles up through the tree or not
*/
EventKeyboard = function (keyCode, isPressed, bubbles) {
cc.Event.call(this, Event.KEYBOARD, bubbles);
@@ -530,7 +561,6 @@ JS.extend(EventKeyboard, cc.Event);
cc.Event.EventMouse = EventMouse;
cc.Event.EventTouch = EventTouch;
-cc.Event.EventFocus = EventFocus;
cc.Event.EventAcceleration = EventAcceleration;
cc.Event.EventKeyboard = EventKeyboard;
diff --git a/cocos2d/core/event-manager/CCTouch.js b/cocos2d/core/event-manager/CCTouch.js
index 2a8e9be731..821f16f342 100644
--- a/cocos2d/core/event-manager/CCTouch.js
+++ b/cocos2d/core/event-manager/CCTouch.js
@@ -24,7 +24,8 @@
****************************************************************************/
/**
- * The touch event class
+ * !#en The touch event class
+ * !#zh 封装了触摸相关的信息。
* @class Touch
*
* @param {Number} x
@@ -43,7 +44,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the current touch location in OpenGL coordinates.
+ * !#en Returns the current touch location in OpenGL coordinates.、
+ * !#zh 获取当前触点位置。
* @method getLocation
* @return {Vec2}
*/
@@ -54,7 +56,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns X axis location value.
+ * !#en Returns X axis location value.
+ * !#zh 获取当前触点 X 轴位置。
* @method getLocationX
* @returns {Number}
*/
@@ -63,7 +66,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns Y axis location value.
+ * !#en Returns Y axis location value.
+ * !#zh 获取当前触点 Y 轴位置。
* @method getLocationY
* @returns {Number}
*/
@@ -72,7 +76,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the previous touch location in OpenGL coordinates.
+ * !#en Returns the previous touch location in OpenGL coordinates.
+ * !#zh 获取触点在上一次事件时的位置对象,对象包含 x 和 y 属性。
* @method getPreviousLocation
* @return {Vec2}
*/
@@ -83,7 +88,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the start touch location in OpenGL coordinates.
+ * !#en Returns the start touch location in OpenGL coordinates.
+ * !#zh 获获取触点落下时的位置对象,对象包含 x 和 y 属性。
* @method getStartLocation
* @returns {Vec2}
*/
@@ -94,7 +100,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the delta distance from the previous touche to the current one in screen coordinates.
+ * !#en Returns the delta distance from the previous touche to the current one in screen coordinates.
+ * !#zh 获取触点距离上一次事件移动的距离对象,对象包含 x 和 y 属性。
* @method getDelta
* @return {Vec2}
*/
@@ -103,7 +110,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the current touch location in screen coordinates.
+ * !#en Returns the current touch location in screen coordinates.
+ * !#zh 获取当前事件在游戏窗口内的坐标位置对象,对象包含 x 和 y 属性。
* @method getLocationInView
* @return {Vec2}
*/
@@ -112,7 +120,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the previous touch location in screen coordinates.
+ * !#en Returns the previous touch location in screen coordinates.
+ * !#zh 获取触点在上一次事件时在游戏窗口中的位置对象,对象包含 x 和 y 属性。
* @method getPreviousLocationInView
* @return {Vec2}
*/
@@ -121,7 +130,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the start touch location in screen coordinates.
+ * !#en Returns the start touch location in screen coordinates.
+ * !#zh 获取触点落下时在游戏窗口中的位置对象,对象包含 x 和 y 属性。
* @method getStartLocationInView
* @return {Vec2}
*/
@@ -130,7 +140,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Returns the id of cc.Touch.
+ * !#en Returns the id of cc.Touch.
+ * !#zh 触点的标识 ID,可以用来在多点触摸中跟踪触点。
* @method getID
* @return {Number}
*/
@@ -139,7 +150,8 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{
},
/**
- * Sets information to touch.
+ * !#en Sets information to touch.
+ * !#zh 设置触摸相关的信息。用于监控触摸事件。
* @method setTouchInfo
* @param {Number} id
* @param {Number} x
diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js
index 537f0b65fb..a55b208d8a 100644
--- a/cocos2d/core/event/event-target.js
+++ b/cocos2d/core/event/event-target.js
@@ -98,6 +98,7 @@ var _doSendEvent = function (owner, event) {
};
/**
+ * !#en
* EventTarget is an object to which an event is dispatched when something has occurred.
* Entity are the most common event targets, but other objects can be event targets too.
*
@@ -116,6 +117,10 @@ var _doSendEvent = function (owner, event) {
* - _getCapturingTargets
* - _getBubblingTargets
*
+ * !#zh
+ * 事件目标是事件触发时,分派的事件对象,Node 是最常见的事件目标,
+ * 但是其他对象也可以是事件目标。
+ *
* @class EventTarget
*/
var EventTarget = function () {
@@ -139,8 +144,8 @@ var EventTarget = function () {
JS.mixin(EventTarget.prototype, {
/**
- * Checks whether the EventTarget object has any callback registered for a specific type of event.
- *
+ * !#en Checks whether the EventTarget object has any callback registered for a specific type of event.
+ * !#zh 检查事件目标对象是否为不特定类型的事件注册的回调。
* @param {String} type - The type of event.
* @param {Boolean} A value of true if a callback of the specified type is registered; false otherwise.
*/
@@ -153,20 +158,27 @@ JS.mixin(EventTarget.prototype, {
},
/**
+ * !#en
* Register an callback of a specific event type on the EventTarget.
* This method is merely an alias to addEventListener.
+ * !#zh
+ * 注册事件目标的特定事件类型回调,仅仅是 addEventListener 的别名。
*
* @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.
* The callback is ignored if it is a duplicate (the callbacks are unique).
* @param {Event} callback.param event
- * @param {Object} [target] - The target to invoke the callback, can be null
- * @param {Boolean} [useCapture=false] - When set to true, the capture argument prevents callback
+ * @param {Object} target - The target to invoke the callback, can be null
+ * @param {Boolean} useCapture - When set to true, the capture argument prevents callback
* 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.
* @return {Function} - Just returns the incoming callback so you can save the anonymous function easier.
+ * @exmaple
+ * node.on(cc.Node.EventType.TOUCH_END, function (event) {
+ * cc.log("this is callback");
+ * }, node);
*/
on: function (type, callback, target, useCapture) {
// Accept also patameters like: (type, callback, useCapture)
@@ -196,17 +208,27 @@ JS.mixin(EventTarget.prototype, {
},
/**
+ * !#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 注册的回调,仅仅是 removeEventListener 的别名。
*
* @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
- * @param {Boolean} [useCapture=false] - Specifies whether the callback being removed was registered as a capturing callback or not.
+ * @param {Object} target - The target to invoke the callback, if it's not given, only callback without target will be removed
+ * @param {Boolean} useCapture - Specifies whether the callback being removed was registered as a capturing callback or not.
* 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
+ * // register touchEnd eventListener
+ * var touchEnd = node.on(cc.Node.EventType.TOUCH_END, function (event) {
+ * cc.log("this is callback");
+ * }, node);
+ * // remove touchEnd eventListener
+ * node.off(cc.Node.EventType.TOUCH_END, touchEnd, node);
*/
off: function (type, callback, target, useCapture) {
// Accept also patameters like: (type, callback, useCapture)
@@ -230,8 +252,8 @@ JS.mixin(EventTarget.prototype, {
},
/**
- * 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
*/
@@ -245,18 +267,26 @@ JS.mixin(EventTarget.prototype, {
},
/**
- * Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.
+ * !#en
+ * Register an callback of a specific event type on the EventTarget,
+ * the callback will remove itself after the first time it is triggered.
+ * !#zh
+ * 注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。
*
* @method once
* @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.
* The callback is ignored if it is a duplicate (the callbacks are unique).
* @param {Event} callback.param event
- * @param {Object} [target] - The target to invoke the callback, can be null
- * @param {Boolean} [useCapture=false] - When set to true, the capture argument prevents callback
+ * @param {Object} target - The target to invoke the callback, can be null
+ * @param {Boolean} useCapture - When set to true, the capture argument prevents callback
* 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
+ * node.once(cc.Node.EventType.TOUCH_END, function (event) {
+ * cc.log("this is callback");
+ * }, node);
*/
once: function (type, callback, target, useCapture) {
var self = this;
@@ -268,7 +298,10 @@ JS.mixin(EventTarget.prototype, {
},
/**
- * Dispatches an event into the event flow. The event target is the EventTarget object upon which the dispatchEvent() method is called.
+ * !#en
+ * Dispatches an event into the event flow.
+ * The event target is the EventTarget object upon which the dispatchEvent() method is called.
+ * !#zh 分发事件到事件流中。
*
* @method dispatchEvent
* @param {Event} event - The Event object that is dispatched into the event flow
@@ -284,12 +317,15 @@ JS.mixin(EventTarget.prototype, {
},
/**
+ * !#en
* Send an event to this object directly, this method will not propagate the event to any other objects.
* The event will be created from the supplied message, you can get the "detail" argument from event.detail.
+ * !#zh
+ * 该对象直接发送事件, 这种方法不会对事件传播到任何其他对象。
*
* @method emit
* @param {String} message - the message to send
- * @param {any} [detail] - whatever argument the message needs
+ * @param {*} [detail] - whatever argument the message needs
*/
emit: function (message, detail) {
if ( typeof message === 'string' ) {
@@ -302,7 +338,7 @@ JS.mixin(EventTarget.prototype, {
}
},
- /**
+ /*
* Get whether the target is active for events.
* The name is for avoiding conflict with user defined functions.
*
@@ -315,7 +351,7 @@ JS.mixin(EventTarget.prototype, {
return true;
},
- /**
+ /*
* Get all the targets listening to the supplied type of event in the target's capturing phase.
* The capturing phase comprises the journey from the root to the last node BEFORE the event target's node.
* The result should save in the array parameter, and MUST SORT from child nodes to parent nodes.
@@ -330,7 +366,7 @@ JS.mixin(EventTarget.prototype, {
},
- /**
+ /*
* Get all the targets listening to the supplied type of event in the target's bubbling phase.
* The bubbling phase comprises any SUBSEQUENT nodes encountered on the return trip to the root of the tree.
* The result should save in the array parameter, and MUST SORT from child nodes to parent nodes.
diff --git a/cocos2d/core/event/event.js b/cocos2d/core/event/event.js
index bd431568a8..6ff2d261ab 100644
--- a/cocos2d/core/event/event.js
+++ b/cocos2d/core/event/event.js
@@ -26,47 +26,53 @@
var JS = require("../platform/js");
/**
- * Base class of all kinds of events.
+ * !#en Base class of all kinds of events.
+ * !#zh 包含事件相关信息的对象。
* @class Event
* @constructor
*/
/**
* @method Event
- * @param {string} type - The name of the event (case-sensitive), e.g. "click", "fire", or "submit"
- * @param {boolean} [bubbles=false] - A boolean indicating whether the event bubbles up through the tree or not
+ * @param {String} type - The name of the event (case-sensitive), e.g. "click", "fire", or "submit"
+ * @param {Boolean} bubbles - A boolean indicating whether the event bubbles up through the tree or not
* @return {Event}
*/
cc.Event = function(type, bubbles) {
/**
- * The name of the event (case-sensitive), e.g. "click", "fire", or "submit".
+ * !#en The name of the event (case-sensitive), e.g. "click", "fire", or "submit".
+ * !#zh 事件类型。
* @property type
* @type {String}
*/
this.type = type;
/**
- * Indicate whether the event bubbles up through the tree or not.
+ * !#en Indicate whether the event bubbles up through the tree or not.
+ * !#zh 表示该事件是否进行冒泡。
* @property bubbles
* @type {Boolean}
*/
this.bubbles = bubbles || false;
/**
- * A reference to the target to which the event was originally dispatched.
+ * !#en A reference to the target to which the event was originally dispatched.
+ * !#zh 最初事件触发的目标
* @property target
* @type {Object}
*/
this.target = null;
/**
- * A reference to the currently registered target for the event.
+ * !#en A reference to the currently registered target for the event.
+ * !#zh 当前目标
* @property currentTarget
* @type {Object}
*/
this.currentTarget = null;
/**
+ * !#en
* Indicates which phase of the event flow is currently being evaluated.
* Returns an integer value represented by 4 constants:
* - Event.NONE = 0
@@ -75,13 +81,13 @@ cc.Event = function(type, bubbles) {
* - Event.BUBBLING_PHASE = 3
* The phases are explained in the [section 3.1, Event dispatch and DOM event flow]
* (http://www.w3.org/TR/DOM-Level-3-Events/#event-flow), of the DOM Level 3 Events specification.
- *
+ * !#zh 事件阶段
* @property eventPhase
* @type {Number}
*/
this.eventPhase = 0;
- /**
+ /*
* Indicates whether or not event.preventDefault() has been called on the event.
* @property _defaultPrevented
* @type {Boolean}
@@ -89,7 +95,7 @@ cc.Event = function(type, bubbles) {
*/
this._defaultPrevented = false;
- /**
+ /*
* Indicates whether or not event.stopPropagation() has been called on the event.
* @property _propagationStopped
* @type {Boolean}
@@ -97,7 +103,7 @@ cc.Event = function(type, bubbles) {
*/
this._propagationStopped = false;
- /**
+ /*
* Indicates whether or not event.stopPropagationImmediate() has been called on the event.
* @property _propagationImmediateStopped
* @type {Boolean}
@@ -109,7 +115,8 @@ cc.Event.prototype = {
constructor: cc.Event,
/**
- * Reset the event for being stored in the object pool.
+ * !#en Reset the event for being stored in the object pool.
+ * !#zh 重置对象池中存储的事件。
* @method unuse
* @returns {String}
*/
@@ -124,7 +131,8 @@ cc.Event.prototype = {
},
/**
- * Reuse the event for being used again by the object pool.
+ * !#en Reuse the event for being used again by the object pool.
+ * !#zh 用于对象池再次使用的事件。
* @method reuse
* @returns {String}
*/
@@ -134,7 +142,9 @@ cc.Event.prototype = {
},
/**
+ * !#en
* If invoked when the cancelable attribute value is true, signals to the operation that caused event to be dispatched that it needs to be canceled.
+ * !#zh 捕获阶段时,阻止传递给最终目标。
* @method preventDefault
*/
preventDefault: function () {
@@ -142,7 +152,8 @@ cc.Event.prototype = {
},
/**
- * Stops propagation for current event.
+ * !#en Stops propagation for current event.
+ * !#zh 停止传递当前事件。
* @method stopPropagation
*/
stopPropagation: function () {
@@ -150,8 +161,9 @@ cc.Event.prototype = {
},
/**
- * Stops propagation for current event immediately,
+ * !#en Stops propagation for current event immediately,
* the event won't even be dispatched to the listeners attached in the current target.
+ * !#zh 立即停止当前事件的传递,事件甚至不会被分派到所连接的当前目标。
* @method stopPropagationImmediate
*/
stopPropagationImmediate: function () {
@@ -159,7 +171,8 @@ cc.Event.prototype = {
},
/**
- * Checks whether the event has been stopped.
+ * !#en Checks whether the event has been stopped.
+ * !#zh 检查该事件是否已经停止传递.
* @method isStopped
* @returns {Boolean}
*/
@@ -168,11 +181,13 @@ cc.Event.prototype = {
},
/**
+ * !#en
*
* Gets current target of the event
* note: It only be available when the event listener is associated with node.
* It returns 0 when the listener is associated with fixed priority.
*
+ * !#zh 获取当前目标节点
* @method getCurrentTarget
* @returns {Node} The target with which the event associates.
*/
@@ -181,7 +196,8 @@ cc.Event.prototype = {
},
/**
- * Gets the event type.
+ * !#en Gets the event type.
+ * !#zh 获取事件类型
* @method getType
* @returns {String}
*/
@@ -192,7 +208,8 @@ cc.Event.prototype = {
//event type
/**
- * Code for event without type.
+ * !#en Code for event without type.
+ * !#zh 没有类型的事件
* @property NO_TYPE
* @final
* @type {string}
@@ -201,31 +218,38 @@ cc.Event.NO_TYPE = 'no_type';
//event phase
/**
- * Events not currently dispatched are in this phase
+ * !#en Events not currently dispatched are in this phase
+ * !#zh 尚未派发事件阶段
* @property NONE
* @type {Number}
* @final
*/
cc.Event.NONE = 0;
/**
+ * !#en
* The capturing phase comprises the journey from the root to the last node before the event target's node
* see http://www.w3.org/TR/DOM-Level-3-Events/#event-flow
+ * !#zh 捕获阶段,包括事件目标节点之前从根节点到最后一个节点的过程。
* @property CAPTURING_PHASE
* @type {Number}
* @final
*/
cc.Event.CAPTURING_PHASE = 1;
/**
+ * !#en
* The target phase comprises only the event target node
* see http://www.w3.org/TR/DOM-Level-3-Events/#event-flow
+ * !#zh 目标阶段仅包括事件目标节点。
* @property AT_TARGET
* @type {Number}
* @final
*/
cc.Event.AT_TARGET = 2;
/**
+ * !#en
* The bubbling phase comprises any subsequent nodes encountered on the return trip to the root of the hierarchy
* see http://www.w3.org/TR/DOM-Level-3-Events/#event-flow
+ * !#zh 冒泡阶段, 包括回程遇到到层次根节点的任何后续节点。
* @property BUBBLING_PHASE
* @type {Number}
* @final
@@ -233,7 +257,8 @@ cc.Event.AT_TARGET = 2;
cc.Event.BUBBLING_PHASE = 3;
/**
- * The Custom event
+ * !#en The Custom event
+ * !#zh 自定义事件
* @class Event.EventCustom
* @constructor
* @extends Event
@@ -242,14 +267,15 @@ cc.Event.BUBBLING_PHASE = 3;
/**
* @method EventCustom
* @param {String} type - The name of the event (case-sensitive), e.g. "click", "fire", or "submit"
- * @param {Boolean} [bubbles=false] - A boolean indicating whether the event bubbles up through the tree or not
+ * @param {Boolean} bubbles - A boolean indicating whether the event bubbles up through the tree or not
* @return {EventCustom}
*/
var EventCustom = function (type, bubbles) {
cc.Event.call(this, type, bubbles);
/**
- * A reference to the detailed data of the event
+ * !#en A reference to the detailed data of the event
+ * !#zh 事件的详细数据
* @property detail
* @type {Object}
*/
@@ -259,7 +285,8 @@ var EventCustom = function (type, bubbles) {
JS.extend(EventCustom, cc.Event);
JS.mixin(EventCustom.prototype, {
/**
- * Sets user data
+ * !#en Sets user data
+ * !#zh 设置用户数据
* @method setUserData
* @param {*} data
*/
@@ -268,7 +295,8 @@ JS.mixin(EventCustom.prototype, {
},
/**
- * Gets user data
+ * !#en Gets user data
+ * !#zh 获取用户数据
* @method getUserData
* @returns {*}
*/
@@ -277,7 +305,8 @@ JS.mixin(EventCustom.prototype, {
},
/**
- * Gets event name
+ * !#en Gets event name
+ * !#zh 获取事件名称
* @method getEventName
* @returns {String}
*/
diff --git a/docs/cocos2d/core/event-manager/CCEventListener/create.js b/docs/cocos2d/core/event-manager/CCEventListener/create.js
index 534b300c52..39d7a99547 100644
--- a/docs/cocos2d/core/event-manager/CCEventListener/create.js
+++ b/docs/cocos2d/core/event-manager/CCEventListener/create.js
@@ -1,10 +1,18 @@
---------
+// Create KEYBOARD EventListener.
cc.EventListener.create({
+ event: cc.EventListener.KEYBOARD,
+ onKeyPressed: function (keyCode, event) {
+ cc.log('pressed key: ' + keyCode);
+ },
+ onKeyReleased: function (keyCode, event) {
+ cc.log('released key: ' + keyCode);
+ }
+});
- event: cc.EventListener.TOUCH_ONE_BY_ONE,
- swallowTouches: true,
- onTouchBegan: function (touch, event) {
- //do something
- return true;
- }
- });
+// Create ACCELERATION EventListener.
+cc.EventListener.create({
+ event: cc.EventListener.ACCELERATION,
+ callback: function (acc, event) {
+ cc.log('acc: ' + keyCode);
+ }
+});
\ No newline at end of file
diff --git a/docs/cocos2d/core/event-manager/CCEventManager/addListener.js b/docs/cocos2d/core/event-manager/CCEventManager/addListener.js
new file mode 100644
index 0000000000..13e955a2be
--- /dev/null
+++ b/docs/cocos2d/core/event-manager/CCEventManager/addListener.js
@@ -0,0 +1,20 @@
+// Add KEYBOARD EventListener To StatusLabel.
+cc.eventManager.addListener({
+ event: cc.EventListener.KEYBOARD,
+ onKeyPressed: function(keyCode, event){
+ var label = event.getCurrentTarget();
+ label.setString("Key " + keyCode.toString() + " was pressed!");
+ },
+ onKeyReleased: function(keyCode, event){
+ var label = event.getCurrentTarget();
+ label.setString("Key " + keyCode.toString() + " was released!");
+ }
+}, statusLabel);
+
+// Create ACCELERATION EventListener To Sprite.
+cc.eventManager.addListener({
+ event: cc.EventListener.ACCELERATION,
+ callback: function(acc, event){
+ //Here processing logic.
+ }
+}, sprite);
\ No newline at end of file
diff --git a/docs/cocos2d/core/event-manager/CCEventManager/removeListener.js b/docs/cocos2d/core/event-manager/CCEventManager/removeListener.js
new file mode 100644
index 0000000000..3aa76bde05
--- /dev/null
+++ b/docs/cocos2d/core/event-manager/CCEventManager/removeListener.js
@@ -0,0 +1,22 @@
+
+// 1. remove eventManager add Listener;
+var mouseListener1 = cc.eventManager.addListener({
+ event: cc.EventListener.MOUSE,
+ onMouseDown: function(keyCode, event){ },
+ onMouseUp: function(keyCode, event){ },
+ onMouseMove: function () { },
+ onMouseScroll: function () { }
+}, node);
+
+cc.eventManager.removeListener(mouseListener1);
+
+// 2. remove eventListener create Listener;
+var mouseListener2 = cc.EventListener.create({
+ event: cc.EventListener.MOUSE,
+ onMouseDown: function(keyCode, event){ },
+ onMouseUp: function(keyCode, event){ },
+ onMouseMove: function () { },
+ onMouseScroll: function () { }
+});
+
+cc.eventManager.removeListener(mouseListener2);