mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-09-24 08:50:16 +00:00
初始化
This commit is contained in:
576
engine/cocos2d/core/event-manager/CCEvent.js
Normal file
576
engine/cocos2d/core/event-manager/CCEvent.js
Normal file
@@ -0,0 +1,576 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var js = cc.js;
|
||||
|
||||
require('../event/event');
|
||||
|
||||
/**
|
||||
* !#en The mouse event
|
||||
* !#zh 鼠标事件类型
|
||||
* @class Event.EventMouse
|
||||
*
|
||||
* @extends Event
|
||||
* @param {Number} eventType - The mouse event type, UP, DOWN, MOVE, CANCELED
|
||||
* @param {Boolean} [bubbles=false] - A boolean indicating whether the event bubbles up through the tree or not
|
||||
*/
|
||||
var EventMouse = function (eventType, bubbles) {
|
||||
cc.Event.call(this, cc.Event.MOUSE, bubbles);
|
||||
this._eventType = eventType;
|
||||
this._button = 0;
|
||||
this._x = 0;
|
||||
this._y = 0;
|
||||
this._prevX = 0;
|
||||
this._prevY = 0;
|
||||
this._scrollX = 0;
|
||||
this._scrollY = 0;
|
||||
};
|
||||
|
||||
js.extend(EventMouse, cc.Event);
|
||||
var proto = EventMouse.prototype;
|
||||
|
||||
/**
|
||||
* !#en Sets scroll data.
|
||||
* !#zh 设置鼠标的滚动数据。
|
||||
* @method setScrollData
|
||||
* @param {Number} scrollX
|
||||
* @param {Number} scrollY
|
||||
*/
|
||||
proto.setScrollData = function (scrollX, scrollY) {
|
||||
this._scrollX = scrollX;
|
||||
this._scrollY = scrollY;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the x axis scroll value.
|
||||
* !#zh 获取鼠标滚动的X轴距离,只有滚动时才有效。
|
||||
* @method getScrollX
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getScrollX = function () {
|
||||
return this._scrollX;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the y axis scroll value.
|
||||
* !#zh 获取滚轮滚动的 Y 轴距离,只有滚动时才有效。
|
||||
* @method getScrollY
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getScrollY = function () {
|
||||
return this._scrollY;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Sets cursor location.
|
||||
* !#zh 设置当前鼠标位置。
|
||||
* @method setLocation
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
proto.setLocation = function (x, y) {
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns cursor location.
|
||||
* !#zh 获取鼠标位置对象,对象包含 x 和 y 属性。
|
||||
* @method getLocation
|
||||
* @return {Vec2} location
|
||||
*/
|
||||
proto.getLocation = function () {
|
||||
return cc.v2(this._x, this._y);
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the current cursor location in screen coordinates.
|
||||
* !#zh 获取当前事件在游戏窗口内的坐标位置对象,对象包含 x 和 y 属性。
|
||||
* @method getLocationInView
|
||||
* @return {Vec2}
|
||||
*/
|
||||
proto.getLocationInView = function() {
|
||||
return cc.v2(this._x, cc.view._designResolutionSize.height - this._y);
|
||||
};
|
||||
|
||||
proto._setPrevCursor = function (x, y) {
|
||||
this._prevX = x;
|
||||
this._prevY = y;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the previous touch location.
|
||||
* !#zh 获取鼠标点击在上一次事件时的位置对象,对象包含 x 和 y 属性。
|
||||
* @method getPreviousLocation
|
||||
* @return {Vec2}
|
||||
*/
|
||||
proto.getPreviousLocation = function () {
|
||||
return cc.v2(this._prevX, this._prevY);
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the delta distance from the previous location to current location.
|
||||
* !#zh 获取鼠标距离上一次事件移动的距离对象,对象包含 x 和 y 属性。
|
||||
* @method getDelta
|
||||
* @return {Vec2}
|
||||
*/
|
||||
proto.getDelta = function () {
|
||||
return cc.v2(this._x - this._prevX, this._y - this._prevY);
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the X axis delta distance from the previous location to current location.
|
||||
* !#zh 获取鼠标距离上一次事件移动的 X 轴距离。
|
||||
* @method getDeltaX
|
||||
* @return {Number}
|
||||
*/
|
||||
proto.getDeltaX = function () {
|
||||
return this._x - this._prevX;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the Y axis delta distance from the previous location to current location.
|
||||
* !#zh 获取鼠标距离上一次事件移动的 Y 轴距离。
|
||||
* @method getDeltaY
|
||||
* @return {Number}
|
||||
*/
|
||||
proto.getDeltaY = function () {
|
||||
return this._y - this._prevY;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Sets mouse button.
|
||||
* !#zh 设置鼠标按键。
|
||||
* @method setButton
|
||||
* @param {Number} button
|
||||
*/
|
||||
proto.setButton = function (button) {
|
||||
this._button = button;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns mouse button.
|
||||
* !#zh 获取鼠标按键。
|
||||
* @method getButton
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getButton = function () {
|
||||
return this._button;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns location X axis data.
|
||||
* !#zh 获取鼠标当前位置 X 轴。
|
||||
* @method getLocationX
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getLocationX = function () {
|
||||
return this._x;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns location Y axis data.
|
||||
* !#zh 获取鼠标当前位置 Y 轴。
|
||||
* @method getLocationY
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getLocationY = function () {
|
||||
return this._y;
|
||||
};
|
||||
|
||||
//Inner event types of MouseEvent
|
||||
/**
|
||||
* !#en The none event code of mouse event.
|
||||
* !#zh 无。
|
||||
* @property NONE
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.NONE = 0;
|
||||
/**
|
||||
* !#en The event type code of mouse down event.
|
||||
* !#zh 鼠标按下事件。
|
||||
* @property DOWN
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.DOWN = 1;
|
||||
/**
|
||||
* !#en The event type code of mouse up event.
|
||||
* !#zh 鼠标按下后释放事件。
|
||||
* @property UP
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.UP = 2;
|
||||
/**
|
||||
* !#en The event type code of mouse move event.
|
||||
* !#zh 鼠标移动事件。
|
||||
* @property MOVE
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.MOVE = 3;
|
||||
/**
|
||||
* !#en The event type code of mouse scroll event.
|
||||
* !#zh 鼠标滚轮事件。
|
||||
* @property SCROLL
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.SCROLL = 4;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse left button.
|
||||
* !#zh 鼠标左键的标签。
|
||||
* @property BUTTON_LEFT
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_LEFT = 0;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse right button (The right button number is 2 on browser).
|
||||
* !#zh 鼠标右键的标签。
|
||||
* @property BUTTON_RIGHT
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_RIGHT = 2;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse middle button (The right button number is 1 on browser).
|
||||
* !#zh 鼠标中键的标签。
|
||||
* @property BUTTON_MIDDLE
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_MIDDLE = 1;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse button 4.
|
||||
* !#zh 鼠标按键 4 的标签。
|
||||
* @property BUTTON_4
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_4 = 3;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse button 5.
|
||||
* !#zh 鼠标按键 5 的标签。
|
||||
* @property BUTTON_5
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_5 = 4;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse button 6.
|
||||
* !#zh 鼠标按键 6 的标签。
|
||||
* @property BUTTON_6
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_6 = 5;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse button 7.
|
||||
* !#zh 鼠标按键 7 的标签。
|
||||
* @property BUTTON_7
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_7 = 6;
|
||||
|
||||
/**
|
||||
* !#en The tag of Mouse button 8.
|
||||
* !#zh 鼠标按键 8 的标签。
|
||||
* @property BUTTON_8
|
||||
* @static
|
||||
* @type {Number}
|
||||
*/
|
||||
EventMouse.BUTTON_8 = 7;
|
||||
|
||||
/**
|
||||
* !#en The touch event
|
||||
* !#zh 触摸事件
|
||||
* @class Event.EventTouch
|
||||
* @constructor
|
||||
* @extends Event
|
||||
*/
|
||||
/**
|
||||
* @method constructor
|
||||
* @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);
|
||||
this._eventCode = 0;
|
||||
this._touches = touchArr || [];
|
||||
/**
|
||||
* !#en The current touch object
|
||||
* !#zh 当前触点对象
|
||||
* @property touch
|
||||
* @type {Touch}
|
||||
*/
|
||||
this.touch = null;
|
||||
// Actually duplicated, because of history issue, currentTouch was in the original design, touch was added in creator engine
|
||||
// They should point to the same object
|
||||
this.currentTouch = null;
|
||||
};
|
||||
|
||||
js.extend(EventTouch, cc.Event);
|
||||
proto = EventTouch.prototype;
|
||||
|
||||
/**
|
||||
* !#en Returns event code.
|
||||
* !#zh 获取事件类型。
|
||||
* @method getEventCode
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getEventCode = function () {
|
||||
return this._eventCode;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns touches of event.
|
||||
* !#zh 获取触摸点的列表。
|
||||
* @method getTouches
|
||||
* @returns {Array}
|
||||
*/
|
||||
proto.getTouches = function () {
|
||||
return this._touches;
|
||||
};
|
||||
|
||||
proto._setEventCode = function (eventCode) {
|
||||
this._eventCode = eventCode;
|
||||
};
|
||||
|
||||
proto._setTouches = function (touches) {
|
||||
this._touches = touches;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Sets touch location.
|
||||
* !#zh 设置当前触点位置
|
||||
* @method setLocation
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
proto.setLocation = function (x, y) {
|
||||
this.touch && this.touch.setTouchInfo(this.touch.getID(), x, y);
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns touch location.
|
||||
* !#zh 获取触点位置。
|
||||
* @method getLocation
|
||||
* @return {Vec2} location
|
||||
*/
|
||||
proto.getLocation = function () {
|
||||
return this.touch ? this.touch.getLocation() : cc.v2();
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the current touch location in screen coordinates.
|
||||
* !#zh 获取当前触点在游戏窗口中的位置。
|
||||
* @method getLocationInView
|
||||
* @return {Vec2}
|
||||
*/
|
||||
proto.getLocationInView = function() {
|
||||
return this.touch ? this.touch.getLocationInView() : cc.v2();
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the previous touch location.
|
||||
* !#zh 获取触点在上一次事件时的位置对象,对象包含 x 和 y 属性。
|
||||
* @method getPreviousLocation
|
||||
* @return {Vec2}
|
||||
*/
|
||||
proto.getPreviousLocation = function () {
|
||||
return this.touch ? this.touch.getPreviousLocation() : cc.v2();
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the start touch location.
|
||||
* !#zh 获取触点落下时的位置对象,对象包含 x 和 y 属性。
|
||||
* @method getStartLocation
|
||||
* @returns {Vec2}
|
||||
*/
|
||||
proto.getStartLocation = function() {
|
||||
return this.touch ? this.touch.getStartLocation() : cc.v2();
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the id of cc.Touch.
|
||||
* !#zh 触点的标识 ID,可以用来在多点触摸中跟踪触点。
|
||||
* @method getID
|
||||
* @return {Number}
|
||||
*/
|
||||
proto.getID = function () {
|
||||
return this.touch ? this.touch.getID() : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the delta distance from the previous location to current location.
|
||||
* !#zh 获取触点距离上一次事件移动的距离对象,对象包含 x 和 y 属性。
|
||||
* @method getDelta
|
||||
* @return {Vec2}
|
||||
*/
|
||||
proto.getDelta = function () {
|
||||
return this.touch ? this.touch.getDelta() : cc.v2();
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the X axis delta distance from the previous location to current location.
|
||||
* !#zh 获取触点距离上一次事件移动的 x 轴距离。
|
||||
* @method getDeltaX
|
||||
* @return {Number}
|
||||
*/
|
||||
proto.getDeltaX = function () {
|
||||
return this.touch ? this.touch.getDelta().x : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns the Y axis delta distance from the previous location to current location.
|
||||
* !#zh 获取触点距离上一次事件移动的 y 轴距离。
|
||||
* @method getDeltaY
|
||||
* @return {Number}
|
||||
*/
|
||||
proto.getDeltaY = function () {
|
||||
return this.touch ? this.touch.getDelta().y : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns location X axis data.
|
||||
* !#zh 获取当前触点 X 轴位置。
|
||||
* @method getLocationX
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getLocationX = function () {
|
||||
return this.touch ? this.touch.getLocationX() : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Returns location Y axis data.
|
||||
* !#zh 获取当前触点 Y 轴位置。
|
||||
* @method getLocationY
|
||||
* @returns {Number}
|
||||
*/
|
||||
proto.getLocationY = function () {
|
||||
return this.touch ? this.touch.getLocationY() : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en The maximum touch numbers
|
||||
* !#zh 最大触摸数量。
|
||||
* @constant
|
||||
* @type {Number}
|
||||
*/
|
||||
EventTouch.MAX_TOUCHES = 5;
|
||||
|
||||
/**
|
||||
* !#en The event type code of touch began event.
|
||||
* !#zh 开始触摸事件
|
||||
* @constant
|
||||
* @type {Number}
|
||||
*/
|
||||
EventTouch.BEGAN = 0;
|
||||
/**
|
||||
* !#en The event type code of touch moved event.
|
||||
* !#zh 触摸后移动事件
|
||||
* @constant
|
||||
* @type {Number}
|
||||
*/
|
||||
EventTouch.MOVED = 1;
|
||||
/**
|
||||
* !#en The event type code of touch ended event.
|
||||
* !#zh 结束触摸事件
|
||||
* @constant
|
||||
* @type {Number}
|
||||
*/
|
||||
EventTouch.ENDED = 2;
|
||||
/**
|
||||
* !#en The event type code of touch cancelled event.
|
||||
* !#zh 取消触摸事件
|
||||
* @constant
|
||||
* @type {Number}
|
||||
*/
|
||||
EventTouch.CANCELED = 3;
|
||||
|
||||
/**
|
||||
* !#en The acceleration event
|
||||
* !#zh 加速度事件
|
||||
* @class Event.EventAcceleration
|
||||
* @extends Event
|
||||
*
|
||||
* @param {Object} acc - The acceleration
|
||||
* @param {Boolean} bubbles - A boolean indicating whether the event bubbles up through the tree or not
|
||||
*/
|
||||
var EventAcceleration = function (acc, bubbles) {
|
||||
cc.Event.call(this, cc.Event.ACCELERATION, bubbles);
|
||||
this.acc = acc;
|
||||
};
|
||||
js.extend(EventAcceleration, cc.Event);
|
||||
|
||||
/**
|
||||
* !#en The keyboard event
|
||||
* !#zh 键盘事件
|
||||
* @class Event.EventKeyboard
|
||||
* @extends Event
|
||||
*
|
||||
* @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 - A boolean indicating whether the event bubbles up through the tree or not
|
||||
*/
|
||||
var EventKeyboard = function (keyCode, isPressed, bubbles) {
|
||||
cc.Event.call(this, cc.Event.KEYBOARD, bubbles);
|
||||
/**
|
||||
* !#en
|
||||
* The keyCode read-only property represents a system and implementation dependent numerical code identifying the unmodified value of the pressed key.
|
||||
* This is usually the decimal ASCII (RFC 20) or Windows 1252 code corresponding to the key.
|
||||
* If the key can't be identified, this value is 0.
|
||||
*
|
||||
* !#zh
|
||||
* keyCode 是只读属性它表示一个系统和依赖于实现的数字代码,可以识别按键的未修改值。
|
||||
* 这通常是十进制 ASCII (RFC20) 或者 Windows 1252 代码,所对应的密钥。
|
||||
* 如果无法识别该键,则该值为 0。
|
||||
*
|
||||
* @property keyCode
|
||||
* @type {Number}
|
||||
*/
|
||||
this.keyCode = keyCode;
|
||||
this.isPressed = isPressed;
|
||||
};
|
||||
js.extend(EventKeyboard, cc.Event);
|
||||
|
||||
cc.Event.EventMouse = EventMouse;
|
||||
cc.Event.EventTouch = EventTouch;
|
||||
cc.Event.EventAcceleration = EventAcceleration;
|
||||
cc.Event.EventKeyboard = EventKeyboard;
|
||||
|
||||
module.exports = cc.Event;
|
559
engine/cocos2d/core/event-manager/CCEventListener.js
Normal file
559
engine/cocos2d/core/event-manager/CCEventListener.js
Normal file
@@ -0,0 +1,559 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var js = require('../platform/js');
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* <p>
|
||||
* The base class of event listener. <br/>
|
||||
* If you need custom listener which with different callback, you need to inherit this class. <br/>
|
||||
* For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard, <br/>
|
||||
* EventListenerTouchOneByOne, EventListenerCustom.
|
||||
* </p>
|
||||
*
|
||||
* !#zh
|
||||
* 封装用户的事件处理逻辑。
|
||||
* 注意:这是一个抽象类,开发者不应该直接实例化这个类,请参考 {{#crossLink "EventListener/create:method"}}cc.EventListener.create{{/crossLink}}。
|
||||
*
|
||||
* @class EventListener
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @method constructor
|
||||
* @param {Number} type
|
||||
* @param {Number} listenerID
|
||||
* @param {Number} callback
|
||||
*/
|
||||
cc.EventListener = function (type, listenerID, callback) {
|
||||
this._onEvent = callback; // Event callback function
|
||||
this._type = type || 0; // Event listener type
|
||||
this._listenerID = listenerID || ""; // Event listener ID
|
||||
this._registered = false; // Whether the listener has been added to dispatcher.
|
||||
|
||||
this._fixedPriority = 0; // The higher the number, the higher the priority, 0 is for scene graph base priority.
|
||||
this._node = null; // scene graph based priority
|
||||
this._target = null;
|
||||
this._paused = true; // Whether the listener is paused
|
||||
this._isEnabled = true; // Whether the listener is enabled
|
||||
};
|
||||
|
||||
cc.EventListener.prototype = {
|
||||
constructor: cc.EventListener,
|
||||
/*
|
||||
* <p>
|
||||
* Sets paused state for the listener
|
||||
* The paused state is only used for scene graph priority listeners.
|
||||
* `EventDispatcher::resumeAllEventListenersForTarget(node)` will set the paused state to `true`,
|
||||
* while `EventDispatcher::pauseAllEventListenersForTarget(node)` will set it to `false`.
|
||||
* @note 1) Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events,
|
||||
* call `setEnabled(false)` instead.
|
||||
* 2) In `Node`'s onEnter and onExit, the `paused state` of the listeners which associated with that node will be automatically updated.
|
||||
* </p>
|
||||
* @param {Boolean} paused
|
||||
* @private
|
||||
*/
|
||||
_setPaused: function (paused) {
|
||||
this._paused = paused;
|
||||
},
|
||||
|
||||
/*
|
||||
* Checks whether the listener is paused.
|
||||
* @returns {Boolean}
|
||||
* @private
|
||||
*/
|
||||
_isPaused: function () {
|
||||
return this._paused;
|
||||
},
|
||||
|
||||
/*
|
||||
* Marks the listener was registered by EventDispatcher.
|
||||
* @param {Boolean} registered
|
||||
* @private
|
||||
*/
|
||||
_setRegistered: function (registered) {
|
||||
this._registered = registered;
|
||||
},
|
||||
|
||||
/*
|
||||
* Checks whether the listener was registered by EventDispatcher
|
||||
* @returns {Boolean}
|
||||
* @private
|
||||
*/
|
||||
_isRegistered: function () {
|
||||
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}
|
||||
* @private
|
||||
*/
|
||||
_getType: function () {
|
||||
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}
|
||||
* @private
|
||||
*/
|
||||
_getListenerID: function () {
|
||||
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
|
||||
* @private
|
||||
*/
|
||||
_setFixedPriority: function (fixedPriority) {
|
||||
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
|
||||
*/
|
||||
_getFixedPriority: function () {
|
||||
return this._fixedPriority;
|
||||
},
|
||||
|
||||
/*
|
||||
* Sets scene graph priority for this listener
|
||||
* @param {cc.Node} node
|
||||
* @private
|
||||
*/
|
||||
_setSceneGraphPriority: function (node) {
|
||||
this._target = node;
|
||||
this._node = node;
|
||||
},
|
||||
|
||||
/*
|
||||
* Gets scene graph priority of this listener
|
||||
* @returns {cc.Node} if it's a fixed priority listener, non-null for scene graph priority listener
|
||||
* @private
|
||||
*/
|
||||
_getSceneGraphPriority: function () {
|
||||
return this._node;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Checks whether the listener is available.
|
||||
* !#zh 检测监听器是否有效
|
||||
* @method checkAvailable
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
checkAvailable: function () {
|
||||
return this._onEvent !== null;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Clones the listener, its subclasses have to override this method.
|
||||
* !#zh 克隆监听器,它的子类必须重写此方法。
|
||||
* @method clone
|
||||
* @returns {EventListener}
|
||||
*/
|
||||
clone: function () {
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#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.
|
||||
*/
|
||||
setEnabled: function(enabled){
|
||||
this._isEnabled = enabled;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Checks whether the listener is enabled
|
||||
* !#zh 检查监听器是否可用。
|
||||
* @method isEnabled
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isEnabled: function(){
|
||||
return this._isEnabled;
|
||||
},
|
||||
|
||||
/*
|
||||
* <p>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<br/>
|
||||
* You will need to retain an object if you created a listener and haven't added it any target node during the same frame.<br/>
|
||||
* Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,<br/>
|
||||
* when you want to use it later, a "Invalid Native Object" error will be raised.<br/>
|
||||
* The retain function can increase a reference count for the native object to avoid it being released,<br/>
|
||||
* you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.<br/>
|
||||
* retain and release function call should be paired in developer's game code.</p>
|
||||
*
|
||||
* @method retain
|
||||
* @see cc.EventListener#release
|
||||
*/
|
||||
retain:function () {
|
||||
},
|
||||
/*
|
||||
* <p>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<br/>
|
||||
* You will need to retain an object if you created a listener and haven't added it any target node during the same frame.<br/>
|
||||
* Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,<br/>
|
||||
* when you want to use it later, a "Invalid Native Object" error will be raised.<br/>
|
||||
* The retain function can increase a reference count for the native object to avoid it being released,<br/>
|
||||
* you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.<br/>
|
||||
* retain and release function call should be paired in developer's game code.</p>
|
||||
*
|
||||
* @method release
|
||||
* @see cc.EventListener#retain
|
||||
*/
|
||||
release:function () {
|
||||
}
|
||||
};
|
||||
|
||||
// event listener type
|
||||
/**
|
||||
* !#en The type code of unknown event listener.
|
||||
* !#zh 未知的事件监听器类型
|
||||
* @property UNKNOWN
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.EventListener.UNKNOWN = 0;
|
||||
/*
|
||||
* !#en The type code of one by one touch event listener.
|
||||
* !#zh 触摸事件监听器类型,触点会一个一个得分开被派发
|
||||
* @property TOUCH_ONE_BY_ONE
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.EventListener.TOUCH_ONE_BY_ONE = 1;
|
||||
/*
|
||||
* !#en The type code of all at once touch event listener.
|
||||
* !#zh 触摸事件监听器类型,触点会被一次性全部派发
|
||||
* @property TOUCH_ALL_AT_ONCE
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.EventListener.TOUCH_ALL_AT_ONCE = 2;
|
||||
/**
|
||||
* !#en The type code of keyboard event listener.
|
||||
* !#zh 键盘事件监听器类型
|
||||
* @property KEYBOARD
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.EventListener.KEYBOARD = 3;
|
||||
/*
|
||||
* !#en The type code of mouse event listener.
|
||||
* !#zh 鼠标事件监听器类型
|
||||
* @property MOUSE
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.EventListener.MOUSE = 4;
|
||||
/**
|
||||
* !#en The type code of acceleration event listener.
|
||||
* !#zh 加速器事件监听器类型
|
||||
* @property ACCELERATION
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.EventListener.ACCELERATION = 6;
|
||||
/*
|
||||
* !#en The type code of custom event listener.
|
||||
* !#zh 自定义事件监听器类型
|
||||
* @property CUSTOM
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.EventListener.CUSTOM = 8;
|
||||
|
||||
var ListenerID = cc.EventListener.ListenerID = {
|
||||
MOUSE: '__cc_mouse',
|
||||
TOUCH_ONE_BY_ONE: '__cc_touch_one_by_one',
|
||||
TOUCH_ALL_AT_ONCE: '__cc_touch_all_at_once',
|
||||
KEYBOARD: '__cc_keyboard',
|
||||
ACCELERATION: '__cc_acceleration',
|
||||
};
|
||||
|
||||
var Custom = function (listenerId, callback) {
|
||||
this._onCustomEvent = callback;
|
||||
cc.EventListener.call(this, cc.EventListener.CUSTOM, listenerId, this._callback);
|
||||
};
|
||||
js.extend(Custom, cc.EventListener);
|
||||
js.mixin(Custom.prototype, {
|
||||
_onCustomEvent: null,
|
||||
|
||||
_callback: function (event) {
|
||||
if (this._onCustomEvent !== null)
|
||||
this._onCustomEvent(event);
|
||||
},
|
||||
|
||||
checkAvailable: function () {
|
||||
return (cc.EventListener.prototype.checkAvailable.call(this) && this._onCustomEvent !== null);
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
return new Custom(this._listenerID, this._onCustomEvent);
|
||||
}
|
||||
});
|
||||
|
||||
var Mouse = function () {
|
||||
cc.EventListener.call(this, cc.EventListener.MOUSE, ListenerID.MOUSE, this._callback);
|
||||
};
|
||||
js.extend(Mouse, cc.EventListener);
|
||||
js.mixin(Mouse.prototype, {
|
||||
onMouseDown: null,
|
||||
onMouseUp: null,
|
||||
onMouseMove: null,
|
||||
onMouseScroll: null,
|
||||
|
||||
_callback: function (event) {
|
||||
var eventType = cc.Event.EventMouse;
|
||||
switch (event._eventType) {
|
||||
case eventType.DOWN:
|
||||
if (this.onMouseDown)
|
||||
this.onMouseDown(event);
|
||||
break;
|
||||
case eventType.UP:
|
||||
if (this.onMouseUp)
|
||||
this.onMouseUp(event);
|
||||
break;
|
||||
case eventType.MOVE:
|
||||
if (this.onMouseMove)
|
||||
this.onMouseMove(event);
|
||||
break;
|
||||
case eventType.SCROLL:
|
||||
if (this.onMouseScroll)
|
||||
this.onMouseScroll(event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var eventListener = new Mouse();
|
||||
eventListener.onMouseDown = this.onMouseDown;
|
||||
eventListener.onMouseUp = this.onMouseUp;
|
||||
eventListener.onMouseMove = this.onMouseMove;
|
||||
eventListener.onMouseScroll = this.onMouseScroll;
|
||||
return eventListener;
|
||||
},
|
||||
|
||||
checkAvailable: function () {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
var TouchOneByOne = function () {
|
||||
cc.EventListener.call(this, cc.EventListener.TOUCH_ONE_BY_ONE, ListenerID.TOUCH_ONE_BY_ONE, null);
|
||||
this._claimedTouches = [];
|
||||
};
|
||||
js.extend(TouchOneByOne, cc.EventListener);
|
||||
js.mixin(TouchOneByOne.prototype, {
|
||||
constructor: TouchOneByOne,
|
||||
_claimedTouches: null,
|
||||
swallowTouches: false,
|
||||
onTouchBegan: null,
|
||||
onTouchMoved: null,
|
||||
onTouchEnded: null,
|
||||
onTouchCancelled: null,
|
||||
|
||||
setSwallowTouches: function (needSwallow) {
|
||||
this.swallowTouches = needSwallow;
|
||||
},
|
||||
|
||||
isSwallowTouches: function(){
|
||||
return this.swallowTouches;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var eventListener = new TouchOneByOne();
|
||||
eventListener.onTouchBegan = this.onTouchBegan;
|
||||
eventListener.onTouchMoved = this.onTouchMoved;
|
||||
eventListener.onTouchEnded = this.onTouchEnded;
|
||||
eventListener.onTouchCancelled = this.onTouchCancelled;
|
||||
eventListener.swallowTouches = this.swallowTouches;
|
||||
return eventListener;
|
||||
},
|
||||
|
||||
checkAvailable: function () {
|
||||
if(!this.onTouchBegan){
|
||||
cc.logID(1801);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
var TouchAllAtOnce = function () {
|
||||
cc.EventListener.call(this, cc.EventListener.TOUCH_ALL_AT_ONCE, ListenerID.TOUCH_ALL_AT_ONCE, null);
|
||||
};
|
||||
js.extend(TouchAllAtOnce, cc.EventListener);
|
||||
js.mixin(TouchAllAtOnce.prototype, {
|
||||
constructor: TouchAllAtOnce,
|
||||
onTouchesBegan: null,
|
||||
onTouchesMoved: null,
|
||||
onTouchesEnded: null,
|
||||
onTouchesCancelled: null,
|
||||
|
||||
clone: function(){
|
||||
var eventListener = new TouchAllAtOnce();
|
||||
eventListener.onTouchesBegan = this.onTouchesBegan;
|
||||
eventListener.onTouchesMoved = this.onTouchesMoved;
|
||||
eventListener.onTouchesEnded = this.onTouchesEnded;
|
||||
eventListener.onTouchesCancelled = this.onTouchesCancelled;
|
||||
return eventListener;
|
||||
},
|
||||
|
||||
checkAvailable: function(){
|
||||
if (this.onTouchesBegan === null && this.onTouchesMoved === null
|
||||
&& this.onTouchesEnded === null && this.onTouchesCancelled === null) {
|
||||
cc.logID(1802);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
//Acceleration
|
||||
var Acceleration = function (callback) {
|
||||
this._onAccelerationEvent = callback;
|
||||
cc.EventListener.call(this, cc.EventListener.ACCELERATION, ListenerID.ACCELERATION, this._callback);
|
||||
};
|
||||
js.extend(Acceleration, cc.EventListener);
|
||||
js.mixin(Acceleration.prototype, {
|
||||
constructor: Acceleration,
|
||||
_onAccelerationEvent: null,
|
||||
|
||||
_callback: function (event) {
|
||||
this._onAccelerationEvent(event.acc, event);
|
||||
},
|
||||
|
||||
checkAvailable: function () {
|
||||
cc.assertID(this._onAccelerationEvent, 1803);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
return new Acceleration(this._onAccelerationEvent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Keyboard
|
||||
var Keyboard = function () {
|
||||
cc.EventListener.call(this, cc.EventListener.KEYBOARD, ListenerID.KEYBOARD, this._callback);
|
||||
};
|
||||
js.extend(Keyboard, cc.EventListener);
|
||||
js.mixin(Keyboard.prototype, {
|
||||
constructor: Keyboard,
|
||||
onKeyPressed: null,
|
||||
onKeyReleased: null,
|
||||
|
||||
_callback: function (event) {
|
||||
if (event.isPressed) {
|
||||
if (this.onKeyPressed)
|
||||
this.onKeyPressed(event.keyCode, event);
|
||||
} else {
|
||||
if (this.onKeyReleased)
|
||||
this.onKeyReleased(event.keyCode, event);
|
||||
}
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var eventListener = new Keyboard();
|
||||
eventListener.onKeyPressed = this.onKeyPressed;
|
||||
eventListener.onKeyReleased = this.onKeyReleased;
|
||||
return eventListener;
|
||||
},
|
||||
|
||||
checkAvailable: function () {
|
||||
if (this.onKeyPressed === null && this.onKeyReleased === null) {
|
||||
cc.logID(1800);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* !#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
|
||||
* @param {Object} argObj a json object
|
||||
* @returns {EventListener}
|
||||
* @static
|
||||
* @example {@link cocos2d/core/event-manager/CCEventListener/create.js}
|
||||
*/
|
||||
cc.EventListener.create = function (argObj) {
|
||||
cc.assertID(argObj&&argObj.event, 1900);
|
||||
|
||||
var listenerType = argObj.event;
|
||||
delete argObj.event;
|
||||
|
||||
var listener = null;
|
||||
if(listenerType === cc.EventListener.TOUCH_ONE_BY_ONE)
|
||||
listener = new TouchOneByOne();
|
||||
else if(listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE)
|
||||
listener = new TouchAllAtOnce();
|
||||
else if(listenerType === cc.EventListener.MOUSE)
|
||||
listener = new Mouse();
|
||||
else if(listenerType === cc.EventListener.CUSTOM){
|
||||
listener = new Custom(argObj.eventName, argObj.callback);
|
||||
delete argObj.eventName;
|
||||
delete argObj.callback;
|
||||
} else if(listenerType === cc.EventListener.KEYBOARD)
|
||||
listener = new Keyboard();
|
||||
else if(listenerType === cc.EventListener.ACCELERATION){
|
||||
listener = new Acceleration(argObj.callback);
|
||||
delete argObj.callback;
|
||||
}
|
||||
|
||||
for(var key in argObj) {
|
||||
listener[key] = argObj[key];
|
||||
}
|
||||
return listener;
|
||||
};
|
||||
|
||||
module.exports = cc.EventListener;
|
1078
engine/cocos2d/core/event-manager/CCEventManager.js
Normal file
1078
engine/cocos2d/core/event-manager/CCEventManager.js
Normal file
File diff suppressed because it is too large
Load Diff
177
engine/cocos2d/core/event-manager/CCTouch.js
Normal file
177
engine/cocos2d/core/event-manager/CCTouch.js
Normal file
@@ -0,0 +1,177 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* !#en The touch event class
|
||||
* !#zh 封装了触摸相关的信息。
|
||||
* @class Touch
|
||||
*
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @param {Number} id
|
||||
*/
|
||||
cc.Touch = function (x, y, id) {
|
||||
this._lastModified = 0;
|
||||
this.setTouchInfo(id, x, y);
|
||||
};
|
||||
cc.Touch.prototype = {
|
||||
constructor: cc.Touch,
|
||||
/**
|
||||
* !#en Returns the current touch location in OpenGL coordinates.、
|
||||
* !#zh 获取当前触点位置。
|
||||
* @method getLocation
|
||||
* @return {Vec2}
|
||||
*/
|
||||
getLocation:function () {
|
||||
return cc.v2(this._point.x, this._point.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns X axis location value.
|
||||
* !#zh 获取当前触点 X 轴位置。
|
||||
* @method getLocationX
|
||||
* @returns {Number}
|
||||
*/
|
||||
getLocationX: function () {
|
||||
return this._point.x;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns Y axis location value.
|
||||
* !#zh 获取当前触点 Y 轴位置。
|
||||
* @method getLocationY
|
||||
* @returns {Number}
|
||||
*/
|
||||
getLocationY: function () {
|
||||
return this._point.y;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the previous touch location in OpenGL coordinates.
|
||||
* !#zh 获取触点在上一次事件时的位置对象,对象包含 x 和 y 属性。
|
||||
* @method getPreviousLocation
|
||||
* @return {Vec2}
|
||||
*/
|
||||
getPreviousLocation:function () {
|
||||
return cc.v2(this._prevPoint.x, this._prevPoint.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the start touch location in OpenGL coordinates.
|
||||
* !#zh 获取触点落下时的位置对象,对象包含 x 和 y 属性。
|
||||
* @method getStartLocation
|
||||
* @returns {Vec2}
|
||||
*/
|
||||
getStartLocation: function() {
|
||||
return cc.v2(this._startPoint.x, this._startPoint.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the delta distance from the previous touche to the current one in screen coordinates.
|
||||
* !#zh 获取触点距离上一次事件移动的距离对象,对象包含 x 和 y 属性。
|
||||
* @method getDelta
|
||||
* @return {Vec2}
|
||||
*/
|
||||
getDelta:function () {
|
||||
return this._point.sub(this._prevPoint);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the current touch location in screen coordinates.
|
||||
* !#zh 获取当前事件在游戏窗口内的坐标位置对象,对象包含 x 和 y 属性。
|
||||
* @method getLocationInView
|
||||
* @return {Vec2}
|
||||
*/
|
||||
getLocationInView: function() {
|
||||
return cc.v2(this._point.x, cc.view._designResolutionSize.height - this._point.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the previous touch location in screen coordinates.
|
||||
* !#zh 获取触点在上一次事件时在游戏窗口中的位置对象,对象包含 x 和 y 属性。
|
||||
* @method getPreviousLocationInView
|
||||
* @return {Vec2}
|
||||
*/
|
||||
getPreviousLocationInView: function(){
|
||||
return cc.v2(this._prevPoint.x, cc.view._designResolutionSize.height - this._prevPoint.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the start touch location in screen coordinates.
|
||||
* !#zh 获取触点落下时在游戏窗口中的位置对象,对象包含 x 和 y 属性。
|
||||
* @method getStartLocationInView
|
||||
* @return {Vec2}
|
||||
*/
|
||||
getStartLocationInView: function(){
|
||||
return cc.v2(this._startPoint.x, cc.view._designResolutionSize.height - this._startPoint.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the id of cc.Touch.
|
||||
* !#zh 触点的标识 ID,可以用来在多点触摸中跟踪触点。
|
||||
* @method getID
|
||||
* @return {Number}
|
||||
*/
|
||||
getID:function () {
|
||||
return this._id;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Sets information to touch.
|
||||
* !#zh 设置触摸相关的信息。用于监控触摸事件。
|
||||
* @method setTouchInfo
|
||||
* @param {Number} id
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
setTouchInfo:function (id, x, y) {
|
||||
this._prevPoint = this._point;
|
||||
this._point = cc.v2(x || 0, y || 0);
|
||||
this._id = id;
|
||||
if(!this._startPointCaptured){
|
||||
this._startPoint = cc.v2(this._point);
|
||||
cc.view._convertPointWithScale(this._startPoint);
|
||||
this._startPointCaptured = true;
|
||||
}
|
||||
},
|
||||
|
||||
_setPoint: function(x, y){
|
||||
if(y === undefined){
|
||||
this._point.x = x.x;
|
||||
this._point.y = x.y;
|
||||
}else{
|
||||
this._point.x = x;
|
||||
this._point.y = y;
|
||||
}
|
||||
},
|
||||
|
||||
_setPrevPoint:function (x, y) {
|
||||
if(y === undefined)
|
||||
this._prevPoint = cc.v2(x.x, x.y);
|
||||
else
|
||||
this._prevPoint = cc.v2(x || 0, y || 0);
|
||||
}
|
||||
};
|
38
engine/cocos2d/core/event-manager/index.js
Normal file
38
engine/cocos2d/core/event-manager/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
require('./CCEvent');
|
||||
require('./CCTouch');
|
||||
require('./CCEventListener');
|
||||
|
||||
var eventManager = require('./CCEventManager');;
|
||||
|
||||
module.exports = eventManager;
|
||||
|
||||
if (CC_TEST) {
|
||||
cc._Test.eventManager = eventManager;
|
||||
}
|
||||
|
Reference in New Issue
Block a user