Phaser.Pointer = function (game, id, pointerMode){ this.game = game; this.id = id; this.type = Phaser.POINTER; this.exists = true ; this.identifier = 0; this.pointerId = null ; this.pointerMode = pointerMode || (Phaser.PointerMode.CURSOR | Phaser.PointerMode.CONTACT); _AN_Write_target('target', this, false , null ); this.button = null ; this.leftButton = new Phaser.DeviceButton(this, Phaser.Pointer.LEFT_BUTTON); this.middleButton = new Phaser.DeviceButton(this, Phaser.Pointer.MIDDLE_BUTTON); this.rightButton = new Phaser.DeviceButton(this, Phaser.Pointer.RIGHT_BUTTON); this.backButton = new Phaser.DeviceButton(this, Phaser.Pointer.BACK_BUTTON); this.forwardButton = new Phaser.DeviceButton(this, Phaser.Pointer.FORWARD_BUTTON); this.eraserButton = new Phaser.DeviceButton(this, Phaser.Pointer.ERASER_BUTTON); 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 = (id === 0); 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); this._clickTrampolines = null ; this._trampolineTargetObject = null ; } ; Phaser.Pointer.NO_BUTTON = 0; Phaser.Pointer.LEFT_BUTTON = 1; Phaser.Pointer.RIGHT_BUTTON = 2; Phaser.Pointer.MIDDLE_BUTTON = 4; Phaser.Pointer.BACK_BUTTON = 8; Phaser.Pointer.FORWARD_BUTTON = 16; Phaser.Pointer.ERASER_BUTTON = 32; Phaser.Pointer.prototype = { resetButtons: function (){ this.isDown = false ; this.isUp = true ; if (this.isMouse) { this.leftButton.reset(); this.middleButton.reset(); this.rightButton.reset(); this.backButton.reset(); this.forwardButton.reset(); this.eraserButton.reset(); } } , processButtonsDown: function (buttons, event){ if (Phaser.Pointer.LEFT_BUTTON & buttons) { this.leftButton.start(event); } if (Phaser.Pointer.RIGHT_BUTTON & buttons) { this.rightButton.start(event); } if (Phaser.Pointer.MIDDLE_BUTTON & buttons) { this.middleButton.start(event); } if (Phaser.Pointer.BACK_BUTTON & buttons) { this.backButton.start(event); } if (Phaser.Pointer.FORWARD_BUTTON & buttons) { this.forwardButton.start(event); } if (Phaser.Pointer.ERASER_BUTTON & buttons) { this.eraserButton.start(event); } } , processButtonsUp: function (button, event){ if (button === Phaser.Mouse.LEFT_BUTTON) { this.leftButton.stop(event); } if (button === Phaser.Mouse.RIGHT_BUTTON) { this.rightButton.stop(event); } if (button === Phaser.Mouse.MIDDLE_BUTTON) { this.middleButton.stop(event); } if (button === Phaser.Mouse.BACK_BUTTON) { this.backButton.stop(event); } if (button === Phaser.Mouse.FORWARD_BUTTON) { this.forwardButton.stop(event); } if (button === 5) { this.eraserButton.stop(event); } } , updateButtons: function (event){ this.button = event.button; var down = (event.type.toLowerCase().substr(-4) === 'down'); if (event.buttons !== undefined) { if (down) { this.processButtonsDown(event.buttons, event); } else { this.processButtonsUp(event.button, event); } } else { if (down) { this.leftButton.start(event); } else { this.leftButton.stop(event); this.rightButton.stop(event); } } if (event.ctrlKey && this.leftButton.isDown) { this.rightButton.start(event); } this.isUp = true ; this.isDown = false ; if (this.leftButton.isDown || this.rightButton.isDown || this.middleButton.isDown || this.backButton.isDown || this.forwardButton.isDown || this.eraserButton.isDown) { this.isUp = false ; this.isDown = true ; } } , start: function (event){ var input = this.game.input; if (event.pointerId) { this.pointerId = event.pointerId; } this.identifier = event.identifier; _AN_Write_target('target', this, false , _AN_Read_target('target', event)); if (this.isMouse) { this.updateButtons(event); } else { this.isDown = true ; this.isUp = false ; } this.active = true ; this.withinGame = true ; this.dirty = false ; this._history = [] ; this._clickTrampolines = null ; this._trampolineTargetObject = null ; this.msSinceLastClick = this.game.time.time - this.timeDown; this.timeDown = this.game.time.time; this._holdSent = false ; this.move(event, true ); this.positionDown.setTo(this.x, this.y); if (input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && input.totalActivePointers === 0)) { input.x = this.x; input.y = this.y; input.position.setTo(this.x, this.y); input.onDown.dispatch(this, event); input.resetSpeed(this.x, this.y); } this._stateReset = false ; this.totalTouches++ ; if (this.targetObject !== null ) { this.targetObject._touchedHandler(this); } return this; } , update: function (){ var input = this.game.input; if (this.active) { if (this.dirty) { if (input.interactiveItems.total > 0) { this.processInteractiveObjects(false ); } this.dirty = false ; } if (this._holdSent === false && this.duration >= input.holdRate) { if (input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && input.totalActivePointers === 0)) { input.onHold.dispatch(this); } this._holdSent = true ; } if (input.recordPointerHistory && this.game.time.time >= this._nextDrop) { this._nextDrop = this.game.time.time + input.recordRate; this._history.push({ x: this.position.x, y: this.position.y} ); if (_AN_Read_length('length', this._history) > input.recordLimit) { this._history.shift(); } } } } , move: function (event, fromClick){ var input = this.game.input; if (input.pollLocked) { return ; } if (fromClick === undefined) { fromClick = false ; } if (event.button !== undefined) { this.button = event.button; } if (fromClick && this.isMouse) { this.updateButtons(event); } 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 && 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) * input.scale.x; this.y = (this.pageY - this.game.scale.offset.y) * input.scale.y; this.position.setTo(this.x, this.y); this.circle.x = this.x; this.circle.y = this.y; if (input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && input.totalActivePointers === 0)) { input.activePointer = this; input.x = this.x; input.y = this.y; input.position.setTo(input.x, input.y); input.circle.x = input.x; input.circle.y = 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', input.moveCallbacks); while (i-- ){ input.moveCallbacks[i].callback.call(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 (input.interactiveItems.total > 0) { this.processInteractiveObjects(fromClick); } return this; } , processInteractiveObjects: function (fromClick){ var highestRenderOrderID = Number.MAX_VALUE; var highestInputPriorityID = -1; var candidateTarget = null ; var currentNode = this.game.input.interactiveItems.first; while (currentNode){ currentNode.checked = false ; if (currentNode.validForInput(highestInputPriorityID, highestRenderOrderID, false )) { currentNode.checked = true ; if ((fromClick && currentNode.checkPointerDown(this, true )) || (!fromClick && currentNode.checkPointerOver(this, true ))) { highestRenderOrderID = currentNode.sprite.renderOrderID; highestInputPriorityID = currentNode.priorityID; candidateTarget = currentNode; } } currentNode = this.game.input.interactiveItems.next; } var currentNode = this.game.input.interactiveItems.first; while (currentNode){ if (!currentNode.checked && currentNode.validForInput(highestInputPriorityID, highestRenderOrderID, true )) { if ((fromClick && currentNode.checkPointerDown(this, false )) || (!fromClick && currentNode.checkPointerOver(this, false ))) { highestRenderOrderID = currentNode.sprite.renderOrderID; highestInputPriorityID = currentNode.priorityID; candidateTarget = currentNode; } } currentNode = this.game.input.interactiveItems.next; } if (candidateTarget === null ) { if (this.targetObject) { this.targetObject._pointerOutHandler(this); this.targetObject = null ; } } else { if (this.targetObject === null ) { this.targetObject = candidateTarget; candidateTarget._pointerOverHandler(this); } else { if (this.targetObject === candidateTarget) { if (candidateTarget.update(this) === false ) { this.targetObject = null ; } } else { this.targetObject._pointerOutHandler(this); this.targetObject = candidateTarget; this.targetObject._pointerOverHandler(this); } } } return (this.targetObject !== null ); } , leave: function (event){ this.withinGame = false ; this.move(event, false ); } , stop: function (event){ var input = this.game.input; if (this._stateReset && this.withinGame) { event.preventDefault(); return ; } this.timeUp = this.game.time.time; if (input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && input.totalActivePointers === 0)) { input.onUp.dispatch(this, event); if (this.duration >= 0 && this.duration <= input.tapRate) { if (this.timeUp - this.previousTapTime < input.doubleTapRate) { input.onTap.dispatch(this, true ); } else { input.onTap.dispatch(this, false ); } this.previousTapTime = this.timeUp; } } if (this.isMouse) { this.updateButtons(event); } else { this.isDown = false ; this.isUp = true ; } if (this.id > 0) { this.active = false ; } this.withinGame = this.game.scale.bounds.contains(event.pageX, event.pageY); this.pointerId = null ; this.identifier = null ; this.positionUp.setTo(this.x, this.y); if (this.isMouse === false ) { input.currentPointers-- ; } input.interactiveItems.callAll('_releasedHandler', this); if (this._clickTrampolines) { this._trampolineTargetObject = this.targetObject; } this.targetObject = null ; return this; } , justPressed: function (duration){ duration = duration || this.game.input.justPressedRate; return (this.isDown === true && (this.timeDown + duration) > this.game.time.time); } , justReleased: function (duration){ duration = duration || this.game.input.justReleasedRate; return (this.isUp && (this.timeUp + duration) > this.game.time.time); } , addClickTrampoline: function (name, callback, callbackContext, callbackArgs){ if (!this.isDown) { return ; } var trampolines = (this._clickTrampolines = this._clickTrampolines || [] ); for (var i = 0; i < _AN_Read_length('length', trampolines); i++ ){ if (trampolines[i].name === name) { trampolines.splice(i, 1); break ; } } trampolines.push({ name: name, targetObject: this.targetObject, callback: callback, callbackContext: callbackContext, callbackArgs: callbackArgs} ); } , processClickTrampolines: function (){ var trampolines = this._clickTrampolines; if (!trampolines) { return ; } for (var i = 0; i < _AN_Read_length('length', trampolines); i++ ){ var trampoline = trampolines[i]; if (trampoline.targetObject === this._trampolineTargetObject) { trampoline.callback.apply(trampoline.callbackContext, trampoline.callbackArgs); } } this._clickTrampolines = null ; this._trampolineTargetObject = null ; } , reset: function (){ if (this.isMouse === false ) { this.active = false ; } this.pointerId = null ; this.identifier = null ; this.dirty = false ; this.totalTouches = 0; this._holdSent = false ; this._history.length = 0; this._stateReset = true ; this.resetButtons(); 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.time - 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; } } ); Phaser.PointerMode = { CURSOR: 1 << 0, CONTACT: 1 << 1} ;