Phaser.Mouse = function (game){ this.game = game; this.callbackContext = this.game; this.mouseDownCallback = null ; this.mouseMoveCallback = null ; this.mouseUpCallback = null ; this.mouseOutCallback = null ; this.mouseOverCallback = null ; this.mouseWheelCallback = null ; this.capture = false ; this.button = -1; this.wheelDelta = 0; this.disabled = false ; this.locked = false ; this.stopOnGameOut = false ; this.pointerLock = new Phaser.Signal(); this.event = null ; this._onMouseDown = null ; this._onMouseMove = null ; this._onMouseUp = null ; this._onMouseOut = null ; this._onMouseOver = null ; this._onMouseWheel = null ; } ; Phaser.Mouse.NO_BUTTON = -1; Phaser.Mouse.LEFT_BUTTON = 0; Phaser.Mouse.MIDDLE_BUTTON = 1; Phaser.Mouse.RIGHT_BUTTON = 2; Phaser.Mouse.WHEEL_UP = 1; Phaser.Mouse.WHEEL_DOWN = -1; Phaser.Mouse.prototype = { start: function (){ if (this.game.device.android && this.game.device.chrome === false ) { return ; } if (this._onMouseDown !== null ) { return ; } var _this = this; this._onMouseDown = function (event){ return _this.onMouseDown(event); } ; this._onMouseMove = function (event){ return _this.onMouseMove(event); } ; this._onMouseUp = function (event){ return _this.onMouseUp(event); } ; this._onMouseUpGlobal = function (event){ return _this.onMouseUpGlobal(event); } ; this._onMouseOut = function (event){ return _this.onMouseOut(event); } ; this._onMouseOver = function (event){ return _this.onMouseOver(event); } ; this._onMouseWheel = function (event){ return _this.onMouseWheel(event); } ; this.game.canvas.addEventListener('mousedown', this._onMouseDown, true ); this.game.canvas.addEventListener('mousemove', this._onMouseMove, true ); this.game.canvas.addEventListener('mouseup', this._onMouseUp, true ); if (!this.game.device.cocoonJS) { window.addEventListener('mouseup', this._onMouseUpGlobal, true ); this.game.canvas.addEventListener('mouseover', this._onMouseOver, true ); this.game.canvas.addEventListener('mouseout', this._onMouseOut, true ); this.game.canvas.addEventListener('mousewheel', this._onMouseWheel, true ); this.game.canvas.addEventListener('DOMMouseScroll', this._onMouseWheel, true ); } } , onMouseDown: function (event){ this.event = event; if (this.capture) { event.preventDefault(); } this.button = event.button; if (this.mouseDownCallback) { this.mouseDownCallback.call(this.callbackContext, event); } if (this.game.input.disabled || this.disabled) { return ; } event.identifier = 0; this.game.input.mousePointer.start(event); } , onMouseMove: function (event){ this.event = event; if (this.capture) { event.preventDefault(); } if (this.mouseMoveCallback) { this.mouseMoveCallback.call(this.callbackContext, event); } if (this.game.input.disabled || this.disabled) { return ; } event.identifier = 0; this.game.input.mousePointer.move(event); } , onMouseUp: function (event){ this.event = event; if (this.capture) { event.preventDefault(); } this.button = Phaser.Mouse.NO_BUTTON; if (this.mouseUpCallback) { this.mouseUpCallback.call(this.callbackContext, event); } if (this.game.input.disabled || this.disabled) { return ; } event.identifier = 0; this.game.input.mousePointer.stop(event); } , onMouseUpGlobal: function (event){ if (!this.game.input.mousePointer.withinGame) { this.button = Phaser.Mouse.NO_BUTTON; if (this.mouseUpCallback) { this.mouseUpCallback.call(this.callbackContext, event); } event.identifier = 0; this.game.input.mousePointer.stop(event); } } , onMouseOut: function (event){ this.event = event; if (this.capture) { event.preventDefault(); } this.game.input.mousePointer.withinGame = false ; if (this.mouseOutCallback) { this.mouseOutCallback.call(this.callbackContext, event); } if (this.game.input.disabled || this.disabled) { return ; } if (this.stopOnGameOut) { event.identifier = 0; this.game.input.mousePointer.stop(event); } } , onMouseWheel: function (event){ this.event = event; if (this.capture) { event.preventDefault(); } this.wheelDelta = Math.max(-1, Math.min(1, (event.wheelDelta || - event.detail))); if (this.mouseWheelCallback) { this.mouseWheelCallback.call(this.callbackContext, event); } } , onMouseOver: function (event){ this.event = event; if (this.capture) { event.preventDefault(); } this.game.input.mousePointer.withinGame = true ; if (this.mouseOverCallback) { this.mouseOverCallback.call(this.callbackContext, event); } if (this.game.input.disabled || this.disabled) { return ; } } , requestPointerLock: function (){ if (this.game.device.pointerLock) { var element = this.game.canvas; element.requestPointerLock = element.requestPointerLock || element.mozRequestPointerLock || element.webkitRequestPointerLock; element.requestPointerLock(); var _this = this; this._pointerLockChange = function (event){ return _this.pointerLockChange(event); } ; document.addEventListener('pointerlockchange', this._pointerLockChange, true ); document.addEventListener('mozpointerlockchange', this._pointerLockChange, true ); document.addEventListener('webkitpointerlockchange', this._pointerLockChange, true ); } } , pointerLockChange: function (event){ var element = this.game.canvas; if (document.pointerLockElement === element || document.mozPointerLockElement === element || document.webkitPointerLockElement === element) { this.locked = true ; this.pointerLock.dispatch(true , event); } else { this.locked = false ; this.pointerLock.dispatch(false , event); } } , releasePointerLock: function (){ document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock; document.exitPointerLock(); document.removeEventListener('pointerlockchange', this._pointerLockChange, true ); document.removeEventListener('mozpointerlockchange', this._pointerLockChange, true ); document.removeEventListener('webkitpointerlockchange', this._pointerLockChange, true ); } , stop: function (){ this.game.canvas.removeEventListener('mousedown', this._onMouseDown, true ); this.game.canvas.removeEventListener('mousemove', this._onMouseMove, true ); this.game.canvas.removeEventListener('mouseup', this._onMouseUp, true ); this.game.canvas.removeEventListener('mouseover', this._onMouseOver, true ); this.game.canvas.removeEventListener('mouseout', this._onMouseOut, true ); this.game.canvas.removeEventListener('mousewheel', this._onMouseWheel, true ); this.game.canvas.removeEventListener('DOMMouseScroll', this._onMouseWheel, true ); window.removeEventListener('mouseup', this._onMouseUpGlobal, true ); document.removeEventListener('pointerlockchange', this._pointerLockChange, true ); document.removeEventListener('mozpointerlockchange', this._pointerLockChange, true ); document.removeEventListener('webkitpointerlockchange', this._pointerLockChange, true ); } } ; Phaser.Mouse.prototype.constructor = Phaser.Mouse;