Phaser.Input = function (game){ this.game = game; this.hitCanvas = null ; this.hitContext = null ; } ; Phaser.Input.MOUSE_OVERRIDES_TOUCH = 0; Phaser.Input.TOUCH_OVERRIDES_MOUSE = 1; Phaser.Input.MOUSE_TOUCH_COMBINE = 2; Phaser.Input.prototype = { game: null , pollRate: 0, _pollCounter: 0, _oldPosition: null , _x: 0, _y: 0, disabled: false , multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE, position: null , speed: null , circle: null , scale: null , maxPointers: 10, currentPointers: 0, tapRate: 200, doubleTapRate: 300, holdRate: 2000, justPressedRate: 200, justReleasedRate: 200, recordPointerHistory: false , recordRate: 100, recordLimit: 100, pointer1: null , pointer2: null , pointer3: null , pointer4: null , pointer5: null , pointer6: null , pointer7: null , pointer8: null , pointer9: null , pointer10: null , activePointer: null , mousePointer: null , mouse: null , keyboard: null , touch: null , mspointer: null , onDown: null , onUp: null , onTap: null , onHold: null , interactiveItems: new Phaser.LinkedList(), boot: function (){ this.mousePointer = new Phaser.Pointer(this.game, 0); this.pointer1 = new Phaser.Pointer(this.game, 1); this.pointer2 = new Phaser.Pointer(this.game, 2); this.mouse = new Phaser.Mouse(this.game); this.keyboard = new Phaser.Keyboard(this.game); this.touch = new Phaser.Touch(this.game); this.mspointer = new Phaser.MSPointer(this.game); this.onDown = new Phaser.Signal(); this.onUp = new Phaser.Signal(); this.onTap = new Phaser.Signal(); this.onHold = new Phaser.Signal(); this.scale = new Phaser.Point(1, 1); this.speed = new Phaser.Point(); this.position = new Phaser.Point(); this._oldPosition = new Phaser.Point(); this.circle = new Phaser.Circle(0, 0, 44); this.activePointer = this.mousePointer; this.currentPointers = 0; this.hitCanvas = _AN_Call_createelement('createElement', document, 'canvas'); this.hitCanvas.width = 1; this.hitCanvas.height = 1; this.hitContext = this.hitCanvas.getContext('2d'); this.mouse.start(); this.keyboard.start(); this.touch.start(); this.mspointer.start(); this.mousePointer.active = true ; } , destroy: function (){ this.mouse.stop(); this.keyboard.stop(); this.touch.stop(); this.mspointer.stop(); } , addPointer: function (){ var next = 0; for (var i = 10; i > 0; i-- ){ if (this['pointer' + i] === null ) { next = i; } } if (next == 0) { console.warn("You can only have 10 Pointer objects"); return null ; } else { this['pointer' + next] = new Phaser.Pointer(this.game, next); return this['pointer' + next]; } } , update: function (){ if (this.pollRate > 0 && this._pollCounter < this.pollRate) { this._pollCounter++ ; return ; } this.speed.x = this.position.x - this._oldPosition.x; this.speed.y = this.position.y - this._oldPosition.y; this._oldPosition.copyFrom(this.position); this.mousePointer.update(); this.pointer1.update(); this.pointer2.update(); if (this.pointer3) { this.pointer3.update(); } if (this.pointer4) { this.pointer4.update(); } if (this.pointer5) { this.pointer5.update(); } if (this.pointer6) { this.pointer6.update(); } if (this.pointer7) { this.pointer7.update(); } if (this.pointer8) { this.pointer8.update(); } if (this.pointer9) { this.pointer9.update(); } if (this.pointer10) { this.pointer10.update(); } this._pollCounter = 0; } , reset: function (hard){ if (this.game.isBooted == false ) { return ; } if (typeof hard == 'undefined') { hard = false ; } this.keyboard.reset(); this.mousePointer.reset(); for (var i = 1; i <= 10; i++ ){ if (this['pointer' + i]) { this['pointer' + i].reset(); } } this.currentPointers = 0; _AN_Write_cursor('cursor', this.game.stage.canvas.style, false , "default"); if (hard == true ) { this.onDown.dispose(); this.onUp.dispose(); this.onTap.dispose(); this.onHold.dispose(); this.onDown = new Phaser.Signal(); this.onUp = new Phaser.Signal(); this.onTap = new Phaser.Signal(); this.onHold = new Phaser.Signal(); this.interactiveItems.callAll('reset'); } this._pollCounter = 0; } , resetSpeed: function (x, y){ this._oldPosition.setTo(x, y); this.speed.setTo(0, 0); } , startPointer: function (event){ if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) { return null ; } if (this.pointer1.active == false ) { return this.pointer1.start(event); } else if (this.pointer2.active == false ) { return this.pointer2.start(event); } else { for (var i = 3; i <= 10; i++ ){ if (this['pointer' + i] && this['pointer' + i].active == false ) { return this['pointer' + i].start(event); } } } return null ; } , updatePointer: function (event){ if (this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.move(event); } else if (this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.move(event); } else { for (var i = 3; i <= 10; i++ ){ if (this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) { return this['pointer' + i].move(event); } } } return null ; } , stopPointer: function (event){ if (this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.stop(event); } else if (this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.stop(event); } else { for (var i = 3; i <= 10; i++ ){ if (this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) { return this['pointer' + i].stop(event); } } } return null ; } , getPointer: function (state){ state = state || false ; if (this.pointer1.active == state) { return this.pointer1; } else if (this.pointer2.active == state) { return this.pointer2; } else { for (var i = 3; i <= 10; i++ ){ if (this['pointer' + i] && this['pointer' + i].active == state) { return this['pointer' + i]; } } } return null ; } , getPointerFromIdentifier: function (identifier){ if (this.pointer1.identifier == identifier) { return this.pointer1; } else if (this.pointer2.identifier == identifier) { return this.pointer2; } else { for (var i = 3; i <= 10; i++ ){ if (this['pointer' + i] && this['pointer' + i].identifier == identifier) { return this['pointer' + i]; } } } return null ; } } ; Object.defineProperty(Phaser.Input.prototype, "x", { get: function (){ return this._x; } , set: function (value){ this._x = Math.floor(value); } } ); Object.defineProperty(Phaser.Input.prototype, "y", { get: function (){ return this._y; } , set: function (value){ this._y = Math.floor(value); } } ); Object.defineProperty(Phaser.Input.prototype, "pollLocked", { get: function (){ return (this.pollRate > 0 && this._pollCounter < this.pollRate); } } ); Object.defineProperty(Phaser.Input.prototype, "totalInactivePointers", { get: function (){ return 10 - this.currentPointers; } } ); Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", { get: function (){ this.currentPointers = 0; for (var i = 1; i <= 10; i++ ){ if (this['pointer' + i] && this['pointer' + i].active) { this.currentPointers++ ; } } return this.currentPointers; } } ); Object.defineProperty(Phaser.Input.prototype, "worldX", { get: function (){ return this.game.camera.view.x + this.x; } } ); Object.defineProperty(Phaser.Input.prototype, "worldY", { get: function (){ return this.game.camera.view.y + this.y; } } );