Phaser.Pointer = function (game, id){ this.game = game; this.id = id; this.active = false ; this.position = new Phaser.Point(); this.positionDown = new Phaser.Point(); this.circle = new Phaser.Circle(0, 0, 44); if (id == 0) { this.isMouse = true ; } } ; Phaser.Pointer.prototype = { _holdSent: false , _history: [] , _nextDrop: 0, _stateReset: false , positionDown: null , position: null , circle: null , withinGame: false , clientX: -1, clientY: -1, pageX: -1, pageY: -1, screenX: -1, screenY: -1, x: -1, y: -1, isMouse: false , isDown: false , isUp: true , timeDown: 0, timeUp: 0, previousTapTime: 0, totalTouches: 0, msSinceLastClick: Number.MAX_VALUE, targetObject: null , start: function (event){ this.identifier = event.identifier; _AN_Write_target('target', this, false , _AN_Read_target('target', event)); if (event.button) { this.button = event.button; } this._history.length = 0; this.active = true ; this.withinGame = true ; this.isDown = true ; this.isUp = false ; this.msSinceLastClick = this.game.time.now - this.timeDown; this.timeDown = this.game.time.now; this._holdSent = false ; this.move(event); this.positionDown.setTo(this.x, this.y); if (this.game.input.multiInputOverride == Phaser.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.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); this.game.input.resetSpeed(this.x, this.y); } this._stateReset = false ; this.totalTouches++ ; if (this.isMouse == false ) { this.game.input.currentPointers++ ; } if (this.targetObject !== null ) { this.targetObject.input._touchedHandler(this); } return this; } , update: function (){ if (this.active) { if (this._holdSent == false && this.duration >= this.game.input.holdRate) { if (this.game.input.multiInputOverride == Phaser.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.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){ if (this.game.input.pollLocked) { return ; } if (event.button) { 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; this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x; this.y = (this.pageY - this.game.stage.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.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.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; } if (this.game.paused) { return this; } if (this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true ) { if (this.targetObject.input.update(this) == false ) { this.targetObject = null ; } return this; } this._highestRenderOrderID = -1; this._highestRenderObject = -1; this._highestInputPriorityID = -1; for (var i = 0; i < this.game.input.totalTrackedObjects; i++ ){ if (this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) { if (this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID)) { this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID; this._highestRenderObject = i; this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID; } } } if (this._highestRenderObject == -1) { if (this.targetObject !== null ) { this.targetObject.input._pointerOutHandler(this); this.targetObject = null ; } } else { if (this.targetObject == null ) { this.targetObject = this.game.input.inputObjects[this._highestRenderObject]; this.targetObject.input._pointerOverHandler(this); } else { if (this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) { if (this.targetObject.input.update(this) == false ) { this.targetObject = null ; } } else { this.targetObject.input._pointerOutHandler(this); this.targetObject = this.game.input.inputObjects[this._highestRenderObject]; this.targetObject.input._pointerOverHandler(this); } } } return this; } , leave: function (event){ this.withinGame = false ; this.move(event); } , stop: function (event){ if (this._stateReset) { event.preventDefault(); return ; } this.timeUp = this.game.time.now; if (this.game.input.multiInputOverride == Phaser.Mouse_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Mouse_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Touch_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) { this.game.input.onUp.dispatch(this); 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 ; if (this.isMouse == false ) { this.game.input.currentPointers-- ; } for (var i = 0; i < this.game.input.totalTrackedObjects; i++ ){ if (this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) { this.game.input.inputObjects[i].input._releasedHandler(this); } } if (this.targetObject) { this.targetObject.input._releasedHandler(this); } this.targetObject = null ; return this; } , justPressed: function (duration){ if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; } return (this.isDown === true && (this.timeDown + duration) > this.game.time.now); } , justReleased: function (duration){ if (typeof duration === "undefined") { 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.identifier = null ; this.isDown = false ; this.isUp = true ; this.totalTouches = 0; this._holdSent = false ; this._history.length = 0; this._stateReset = true ; if (this.targetObject && this.targetObject.input) { this.targetObject.input._releasedHandler(this); } this.targetObject = null ; } , toString: function (){ return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]"; } } ; Object.defineProperty(Phaser.Pointer.prototype, "duration", { get: function (){ if (this.isUp) { return -1; } return this.game.time.now - this.timeDown; } , enumerable: true , configurable: true } ); Object.defineProperty(Phaser.Pointer.prototype, "worldX", { get: function (){ return this.game.world.camera.worldView.x + this.x; } , enumerable: true , configurable: true } ); Object.defineProperty(Phaser.Pointer.prototype, "worldY", { get: function (){ return this.game.world.camera.worldView.y + this.y; } , enumerable: true , configurable: true } );