Phaser.Pointer = function (game, id){ this.game = game; this.id = id; this.type = Phaser.POINTER; this.exists = true ; this.identifier = 0; this.pointerId = null ; _AN_Write_target('target', this, false , null ); this.button = null ; this._holdSent = false ; this._history = [] ; this._nextDrop = 0; this._stateReset = false ; this.withinGame = false ; this.clientX = -1; this.clientY = -1; this.pageX = -1; this.pageY = -1; this.screenX = -1; this.screenY = -1; this.rawMovementX = 0; this.rawMovementY = 0; this.movementX = 0; this.movementY = 0; this.x = -1; this.y = -1; this.isMouse = false ; this.isDown = false ; this.isUp = true ; this.timeDown = 0; this.timeUp = 0; this.previousTapTime = 0; this.totalTouches = 0; this.msSinceLastClick = Number.MAX_VALUE; this.targetObject = null ; this.active = false ; this.dirty = false ; this.position = new Phaser.Point(); this.positionDown = new Phaser.Point(); this.positionUp = new Phaser.Point(); this.circle = new Phaser.Circle(0, 0, 44); if (id === 0) { this.isMouse = true ; } } ; Phaser.Pointer.prototype = { start: function (event){ if (event.pointerId) { this.pointerId = event.pointerId; } this.identifier = event.identifier; _AN_Write_target('target', this, false , _AN_Read_target('target', event)); if (typeof event.button !== 'undefined') { this.button = event.button; } this._history = [] ; this.active = true ; this.withinGame = true ; this.isDown = true ; this.isUp = false ; this.dirty = false ; this.msSinceLastClick = this.game.time.now - this.timeDown; this.timeDown = this.game.time.now; this._holdSent = false ; this.move(event, true ); this.positionDown.setTo(this.x, this.y); if (this.game.input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.x = this.x; this.game.input.y = this.y; this.game.input.position.setTo(this.x, this.y); this.game.input.onDown.dispatch(this, event); this.game.input.resetSpeed(this.x, this.y); } this._stateReset = false ; this.totalTouches++ ; if (!this.isMouse) { this.game.input.currentPointers++ ; } if (this.targetObject !== null ) { this.targetObject._touchedHandler(this); } return this; } , update: function (){ if (this.active) { if (this.dirty) { if (this.game.input.interactiveItems.total > 0) { this.processInteractiveObjects(true ); } this.dirty = false ; } if (this._holdSent === false && this.duration >= this.game.input.holdRate) { if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.onHold.dispatch(this); } this._holdSent = true ; } if (this.game.input.recordPointerHistory && this.game.time.now >= this._nextDrop) { this._nextDrop = this.game.time.now + this.game.input.recordRate; this._history.push({ x: this.position.x, y: this.position.y} ); if (_AN_Read_length('length', this._history) > this.game.input.recordLimit) { this._history.shift(); } } } } , move: function (event, fromClick){ if (this.game.input.pollLocked) { return ; } if (typeof fromClick === 'undefined') { fromClick = false ; } if (typeof event.button !== 'undefined') { this.button = event.button; } this.clientX = event.clientX; this.clientY = event.clientY; this.pageX = event.pageX; this.pageY = event.pageY; this.screenX = event.screenX; this.screenY = event.screenY; if (this.isMouse && this.game.input.mouse.locked && !fromClick) { this.rawMovementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0; this.rawMovementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0; this.movementX += this.rawMovementX; this.movementY += this.rawMovementY; } this.x = (this.pageX - this.game.scale.offset.x) * this.game.input.scale.x; this.y = (this.pageY - this.game.scale.offset.y) * this.game.input.scale.y; this.position.setTo(this.x, this.y); this.circle.x = this.x; this.circle.y = this.y; if (this.game.input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.activePointer = this; this.game.input.x = this.x; this.game.input.y = this.y; this.game.input.position.setTo(this.game.input.x, this.game.input.y); this.game.input.circle.x = this.game.input.x; this.game.input.circle.y = this.game.input.y; } this.withinGame = this.game.scale.bounds.contains(this.pageX, this.pageY); if (this.game.paused) { return this; } var i = _AN_Read_length('length', this.game.input.moveCallbacks); while (i-- ){ this.game.input.moveCallbacks[i].callback.call(this.game.input.moveCallbacks[i].context, this, this.x, this.y, fromClick); } if (this.targetObject !== null && this.targetObject.isDragged === true ) { if (this.targetObject.update(this) === false ) { this.targetObject = null ; } } else if (this.game.input.interactiveItems.total > 0) { this.processInteractiveObjects(fromClick); } return this; } , processInteractiveObjects: function (fromClick){ this.game.input.interactiveItems.setAll('checked', false ); this._highestRenderOrderID = Number.MAX_SAFE_INTEGER; this._highestRenderObject = null ; this._highestInputPriorityID = -1; var currentNode = this.game.input.interactiveItems.first; do { if (currentNode && currentNode.validForInput(this._highestInputPriorityID, this._highestRenderOrderID, false )) { currentNode.checked = true ; if ((fromClick && currentNode.checkPointerDown(this, true )) || (!fromClick && currentNode.checkPointerOver(this, true ))) { this._highestRenderOrderID = currentNode.sprite._cache[3]; this._highestInputPriorityID = currentNode.priorityID; this._highestRenderObject = currentNode; } } currentNode = this.game.input.interactiveItems.next; } while(currentNode !== null )var currentNode = this.game.input.interactiveItems.first; do { if (currentNode && !currentNode.checked && currentNode.validForInput(this._highestInputPriorityID, this._highestRenderOrderID, true )) { if ((fromClick && currentNode.checkPointerDown(this, false )) || (!fromClick && currentNode.checkPointerOver(this, false ))) { this._highestRenderOrderID = currentNode.sprite._cache[3]; this._highestInputPriorityID = currentNode.priorityID; this._highestRenderObject = currentNode; } } currentNode = this.game.input.interactiveItems.next; } while(currentNode !== null )if (this._highestRenderObject === null ) { if (this.targetObject) { this.targetObject._pointerOutHandler(this); this.targetObject = null ; } } else { if (this.targetObject === null ) { this.targetObject = this._highestRenderObject; this._highestRenderObject._pointerOverHandler(this); } else { if (this.targetObject === this._highestRenderObject) { if (this._highestRenderObject.update(this) === false ) { this.targetObject = null ; } } else { this.targetObject._pointerOutHandler(this); this.targetObject = this._highestRenderObject; this.targetObject._pointerOverHandler(this); } } } return (this.targetObject !== null ); } , leave: function (event){ this.withinGame = false ; this.move(event, false ); } , stop: function (event){ if (this._stateReset) { event.preventDefault(); return ; } this.timeUp = this.game.time.now; if (this.game.input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.onUp.dispatch(this, event); if (this.duration >= 0 && this.duration <= this.game.input.tapRate) { if (this.timeUp - this.previousTapTime < this.game.input.doubleTapRate) { this.game.input.onTap.dispatch(this, true ); } else { this.game.input.onTap.dispatch(this, false ); } this.previousTapTime = this.timeUp; } } if (this.id > 0) { this.active = false ; } this.withinGame = false ; this.isDown = false ; this.isUp = true ; this.pointerId = null ; this.identifier = null ; this.positionUp.setTo(this.x, this.y); if (this.isMouse === false ) { this.game.input.currentPointers-- ; } this.game.input.interactiveItems.callAll('_releasedHandler', this); this.targetObject = null ; return this; } , justPressed: function (duration){ duration = duration || this.game.input.justPressedRate; return (this.isDown === true && (this.timeDown + duration) > this.game.time.now); } , justReleased: function (duration){ duration = duration || this.game.input.justReleasedRate; return (this.isUp === true && (this.timeUp + duration) > this.game.time.now); } , reset: function (){ if (this.isMouse === false ) { this.active = false ; } this.pointerId = null ; this.identifier = null ; this.dirty = false ; this.isDown = false ; this.isUp = true ; this.totalTouches = 0; this._holdSent = false ; this._history.length = 0; this._stateReset = true ; if (this.targetObject) { this.targetObject._releasedHandler(this); } this.targetObject = null ; } , resetMovement: function (){ this.movementX = 0; this.movementY = 0; } } ; Phaser.Pointer.prototype.constructor = Phaser.Pointer; Object.defineProperty(Phaser.Pointer.prototype, "duration", { get: function (){ if (this.isUp) { return -1; } return this.game.time.now - this.timeDown; } } ); Object.defineProperty(Phaser.Pointer.prototype, "worldX", { get: function (){ return this.game.world.camera.x + this.x; } } ); Object.defineProperty(Phaser.Pointer.prototype, "worldY", { get: function (){ return this.game.world.camera.y + this.y; } } );