From a174bbc6b36c49e97ba680673f27a5a626cada0d Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 8 Aug 2013 03:05:59 +0100 Subject: [PATCH] Vastly optimised InputManager and Pointer is now aware of which camera it is over. --- Phaser/cameras/CameraManager.ts | 27 ++- Phaser/input/InputHandler.ts | 8 +- Phaser/input/InputManager.ts | 341 ++++++++---------------------- Phaser/input/Pointer.ts | 26 ++- Phaser/tilemap/Tilemap.ts | 2 +- Phaser/utils/DebugUtils.ts | 15 +- README.md | 5 +- Tests/Tests.csproj | 4 + Tests/buttons/camera buttons.js | 26 +++ Tests/buttons/camera buttons.ts | 44 ++++ Tests/camera fx/mirror.js | 2 - Tests/camera fx/mirror.ts | 3 - Tests/cameras/camera alpha.js | 4 +- Tests/cameras/camera alpha.ts | 4 +- Tests/cameras/follow styles.js | 8 +- Tests/cameras/follow styles.ts | 8 +- Tests/mobile/sprite test 1.js | 2 - Tests/mobile/sprite test 1.ts | 3 - Tests/phaser.js | 364 +++++++++++++++----------------- build/phaser.d.ts | 32 +-- build/phaser.js | 364 +++++++++++++++----------------- 21 files changed, 601 insertions(+), 691 deletions(-) create mode 100644 Tests/buttons/camera buttons.js create mode 100644 Tests/buttons/camera buttons.ts diff --git a/Phaser/cameras/CameraManager.ts b/Phaser/cameras/CameraManager.ts index b4094778..bd9a9153 100644 --- a/Phaser/cameras/CameraManager.ts +++ b/Phaser/cameras/CameraManager.ts @@ -26,6 +26,7 @@ module Phaser { this._game = game; this._cameras = []; + this._cameraLength = 0; this.defaultCamera = this.addCamera(x, y, width, height); @@ -44,9 +45,9 @@ module Phaser { private _cameras: Camera[]; /** - * Local helper stores index of next created camera. + * Local container for storing cameras array length. */ - private _cameraInstance: number = 0; + private _cameraLength: number; /** * Helper for sort. @@ -112,11 +113,9 @@ module Phaser { */ public addCamera(x: number, y: number, width: number, height: number): Camera { - var newCam: Camera = new Camera(this._game, this._cameraInstance, x, y, width, height); + var newCam: Camera = new Camera(this._game, this._cameraLength, x, y, width, height); - this._cameras.push(newCam); - - this._cameraInstance++; + this._cameraLength = this._cameras.push(newCam); return newCam; @@ -170,6 +169,22 @@ module Phaser { } + public getCameraUnderPoint(x: number, y: number): Camera { + + // Work through the cameras in reverse as they are rendered in array order + // Return the first camera we find matching the criteria + for (var c = this._cameraLength - 1; c >= 0; c--) + { + if (this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) + { + return this._cameras[c]; + } + } + + return null; + + } + /** * Call this function to sort the Cameras according to a particular value and order (default is their Z value). * The order in which they are sorted determines the render order. If sorted on z then Cameras with a lower z-index value render first. diff --git a/Phaser/input/InputHandler.ts b/Phaser/input/InputHandler.ts index 8f3235c5..0e992acb 100644 --- a/Phaser/input/InputHandler.ts +++ b/Phaser/input/InputHandler.ts @@ -297,7 +297,7 @@ module Phaser.Components { } else { - return SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY()); + return SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY); } } @@ -319,7 +319,7 @@ module Phaser.Components { } else if (this._pointerData[pointer.id].isOver == true) { - if (SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY())) + if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) { this._pointerData[pointer.id].x = pointer.x - this._parent.x; this._pointerData[pointer.id].y = pointer.y - this._parent.y; @@ -413,7 +413,7 @@ module Phaser.Components { this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown; // Only release the InputUp signal if the pointer is still over this sprite - if (SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY())) + if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) { //console.log('releasedHandler: ' + Date.now()); this._parent.events.onInputUp.dispatch(this._parent, pointer); @@ -605,7 +605,7 @@ module Phaser.Components { if (this.dragFromCenter) { - this._parent.transform.centerOn(pointer.worldX(), pointer.worldY()); + this._parent.transform.centerOn(pointer.worldX, pointer.worldY); this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y); } else diff --git a/Phaser/input/InputManager.ts b/Phaser/input/InputManager.ts index 57bc9bb9..2f5bc0ec 100644 --- a/Phaser/input/InputManager.ts +++ b/Phaser/input/InputManager.ts @@ -27,9 +27,6 @@ module Phaser { this.mousePointer = new Pointer(this.game, 0); this.pointer1 = new Pointer(this.game, 1); this.pointer2 = new Pointer(this.game, 2); - this.pointer3 = new Pointer(this.game, 3); - this.pointer4 = new Pointer(this.game, 4); - this.pointer5 = new Pointer(this.game, 5); this.mouse = new Mouse(this.game); this.keyboard = new Keyboard(this.game); @@ -48,8 +45,6 @@ module Phaser { this._oldPosition = new Vec2; this.circle = new Circle(0, 0, 44); - this.camera = this.game.camera; - this.activePointer = this.mousePointer; this.currentPointers = 0; @@ -130,10 +125,14 @@ module Phaser { /** * The camera being used for mouse and touch based pointers to calculate their world coordinates. + * This is only ever the camera set by the most recently active Pointer. + * If you need to know exactly which camera a specific Pointer is over then see Pointer.camera instead. * @property camera * @type {Camera} **/ - public camera: Camera; + public get camera(): Camera { + return this.activePointer.camera; + } /** * Phaser.Mouse handler @@ -318,21 +317,21 @@ module Phaser { * @property pointer3 * @type {Pointer} **/ - public pointer3: Pointer; + public pointer3: Pointer = null; /** * A Pointer object * @property pointer4 * @type {Pointer} **/ - public pointer4: Pointer; + public pointer4: Pointer = null; /** * A Pointer object * @property pointer5 * @type {Pointer} **/ - public pointer5: Pointer; + public pointer5: Pointer = null; /** * A Pointer object @@ -392,7 +391,7 @@ module Phaser { } public set x(value: number) { - this._x = Math.round(value); + this._x = Math.floor(value); } /** @@ -406,11 +405,11 @@ module Phaser { } public set y(value: number) { - this._y = Math.round(value); + this._y = Math.floor(value); } /** - * Add a new Pointer object to the Input Manager. By default Input creates 5 pointer objects for you. If you need more + * Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more * use this to create a new one, up to a maximum of 10. * @method addPointer * @return {Pointer} A reference to the new Pointer object @@ -419,29 +418,12 @@ module Phaser { var next: number = 0; - if (this.pointer10 === null) + for (var i = 10; i > 0; i--) { - next = 10; - } - - if (this.pointer9 === null) - { - next = 9; - } - - if (this.pointer8 === null) - { - next = 8; - } - - if (this.pointer7 === null) - { - next = 7; - } - - if (this.pointer6 === null) - { - next = 6; + if (this['pointer' + i] === null) + { + next = i; + } } if (next == 0) @@ -527,10 +509,10 @@ module Phaser { this.mousePointer.update(); this.pointer1.update(); this.pointer2.update(); - this.pointer3.update(); - this.pointer4.update(); - this.pointer5.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(); } @@ -549,17 +531,14 @@ module Phaser { this.keyboard.reset(); this.mousePointer.reset(); - this.pointer1.reset(); - this.pointer2.reset(); - this.pointer3.reset(); - this.pointer4.reset(); - this.pointer5.reset(); - if (this.pointer6) { this.pointer6.reset(); } - if (this.pointer7) { this.pointer7.reset(); } - if (this.pointer8) { this.pointer8.reset(); } - if (this.pointer9) { this.pointer9.reset(); } - if (this.pointer10) { this.pointer10.reset(); } + for (var i = 1; i <= 10; i++) + { + if (this['pointer' + i]) + { + this['pointer' + i].reset(); + } + } this.currentPointers = 0; @@ -616,45 +595,12 @@ module Phaser { this.currentPointers = 0; - if (this.pointer1.active == true) + for (var i = 1; i <= 10; i++) { - this.currentPointers++; - } - else if (this.pointer2.active == true) - { - this.currentPointers++; - } - else if (this.pointer3.active == true) - { - this.currentPointers++; - } - else if (this.pointer4.active == true) - { - this.currentPointers++; - } - else if (this.pointer5.active == true) - { - this.currentPointers++; - } - else if (this.pointer6 && this.pointer6.active == true) - { - this.currentPointers++; - } - else if (this.pointer7 && this.pointer7.active == true) - { - this.currentPointers++; - } - else if (this.pointer8 && this.pointer8.active == true) - { - this.currentPointers++; - } - else if (this.pointer9 && this.pointer9.active == true) - { - this.currentPointers++; - } - else if (this.pointer10 && this.pointer10.active == true) - { - this.currentPointers++; + if (this['pointer' + i] && this['pointer' + i].active) + { + this.currentPointers++; + } } return this.currentPointers; @@ -683,37 +629,15 @@ module Phaser { { return this.pointer2.start(event); } - else if (this.pointer3.active == false) + else { - return this.pointer3.start(event); - } - else if (this.pointer4.active == false) - { - return this.pointer4.start(event); - } - else if (this.pointer5.active == false) - { - return this.pointer5.start(event); - } - else if (this.pointer6 && this.pointer6.active == false) - { - return this.pointer6.start(event); - } - else if (this.pointer7 && this.pointer7.active == false) - { - return this.pointer7.start(event); - } - else if (this.pointer8 && this.pointer8.active == false) - { - return this.pointer8.start(event); - } - else if (this.pointer9 && this.pointer9.active == false) - { - return this.pointer9.start(event); - } - else if (this.pointer10 && this.pointer10.active == false) - { - return this.pointer10.start(event); + for (var i = 3; i <= 10; i++) + { + if (this['pointer' + i] && this['pointer' + i].active == false) + { + return this['pointer' + i].start(event); + } + } } return null; @@ -729,45 +653,23 @@ module Phaser { public updatePointer(event): Pointer { // Unrolled for speed - if (this.pointer1.active == true && this.pointer1.identifier == event.identifier) + if (this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.move(event); } - else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier) + else if (this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.move(event); } - else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier) + else { - return this.pointer3.move(event); - } - else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier) - { - return this.pointer4.move(event); - } - else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier) - { - return this.pointer5.move(event); - } - else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier) - { - return this.pointer6.move(event); - } - else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier) - { - return this.pointer7.move(event); - } - else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier) - { - return this.pointer8.move(event); - } - else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier) - { - return this.pointer9.move(event); - } - else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier) - { - return this.pointer10.move(event); + 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; @@ -783,45 +685,23 @@ module Phaser { public stopPointer(event): Pointer { // Unrolled for speed - if (this.pointer1.active == true && this.pointer1.identifier == event.identifier) + if (this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.stop(event); } - else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier) + else if (this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.stop(event); } - else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier) + else { - return this.pointer3.stop(event); - } - else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier) - { - return this.pointer4.stop(event); - } - else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier) - { - return this.pointer5.stop(event); - } - else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier) - { - return this.pointer6.stop(event); - } - else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier) - { - return this.pointer7.stop(event); - } - else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier) - { - return this.pointer8.stop(event); - } - else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier) - { - return this.pointer9.stop(event); - } - else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier) - { - return this.pointer10.stop(event); + 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; @@ -845,37 +725,15 @@ module Phaser { { return this.pointer2; } - else if (this.pointer3.active == state) + else { - return this.pointer3; - } - else if (this.pointer4.active == state) - { - return this.pointer4; - } - else if (this.pointer5.active == state) - { - return this.pointer5; - } - else if (this.pointer6 && this.pointer6.active == state) - { - return this.pointer6; - } - else if (this.pointer7 && this.pointer7.active == state) - { - return this.pointer7; - } - else if (this.pointer8 && this.pointer8.active == state) - { - return this.pointer8; - } - else if (this.pointer9 && this.pointer9.active == state) - { - return this.pointer9; - } - else if (this.pointer10 && this.pointer10.active == state) - { - return this.pointer10; + for (var i = 3; i <= 10; i++) + { + if (this['pointer' + i] && this['pointer' + i].active == state) + { + return this['pointer' + i]; + } + } } return null; @@ -899,55 +757,40 @@ module Phaser { { return this.pointer2; } - else if (this.pointer3.identifier == identifier) + else { - return this.pointer3; - } - else if (this.pointer4.identifier == identifier) - { - return this.pointer4; - } - else if (this.pointer5.identifier == identifier) - { - return this.pointer5; - } - else if (this.pointer6 && this.pointer6.identifier == identifier) - { - return this.pointer6; - } - else if (this.pointer7 && this.pointer7.identifier == identifier) - { - return this.pointer7; - } - else if (this.pointer8 && this.pointer8.identifier == identifier) - { - return this.pointer8; - } - else if (this.pointer9 && this.pointer9.identifier == identifier) - { - return this.pointer9; - } - else if (this.pointer10 && this.pointer10.identifier == identifier) - { - return this.pointer10; + for (var i = 3; i <= 10; i++) + { + if (this['pointer' + i] && this['pointer' + i].identifier == identifier) + { + return this['pointer' + i]; + } + } } return null; } - /** - * @param {Camera} [camera] - */ - public getWorldX(camera?: Camera = this.game.camera) { - return camera.worldView.x + this.x; + public get worldX(): number { + + if (this.camera) + { + return (this.camera.worldView.x - this.camera.screenView.x) + this.x; + } + + return null; + } - /** - * @param {Camera} [camera] - */ - public getWorldY(camera?: Camera = this.game.camera) { - return camera.worldView.y + this.y; + public get worldY(): number { + + if (this.camera) + { + return (this.camera.worldView.y - this.camera.screenView.y) + this.y; + } + + return null; } /** diff --git a/Phaser/input/Pointer.ts b/Phaser/input/Pointer.ts index 47dfea58..c71a7213 100644 --- a/Phaser/input/Pointer.ts +++ b/Phaser/input/Pointer.ts @@ -273,20 +273,36 @@ module Phaser { **/ public targetObject = null; + /** + * The top-most Camera that this Pointer is over (if any, null if none). + * If the Pointer is over several cameras that are stacked on-top of each other this is only ever set to the top-most rendered camera. + * @property camera + * @type {Phaser.Camera} + **/ + public camera: Phaser.Camera = null; + /** * Gets the X value of this Pointer in world coordinates based on the given camera. * @param {Camera} [camera] */ - public worldX(camera?: Camera = this.game.input.camera) { - return camera.worldView.x + this.x; + public get worldX() { + if (this.camera) + { + return this.camera.worldView.x + this.x; + } + return null; } /** * Gets the Y value of this Pointer in world coordinates based on the given camera. * @param {Camera} [camera] */ - public worldY(camera?: Camera = this.game.input.camera) { - return camera.worldView.y + this.y; + public get worldY() { + if (this.camera) + { + return this.camera.worldView.y + this.y; + } + return null; } /** @@ -385,6 +401,8 @@ module Phaser { } } + // Check which camera they are over + this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y); } } diff --git a/Phaser/tilemap/Tilemap.ts b/Phaser/tilemap/Tilemap.ts index 57dca52f..3d3d3f43 100644 --- a/Phaser/tilemap/Tilemap.ts +++ b/Phaser/tilemap/Tilemap.ts @@ -427,7 +427,7 @@ module Phaser { */ public getTileFromInputXY(layer?: number = 0):Tile { - return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.getWorldX(), this.game.input.getWorldY())]; + return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.worldX, this.game.input.worldY)]; } diff --git a/Phaser/utils/DebugUtils.ts b/Phaser/utils/DebugUtils.ts index b8419b51..f02a45eb 100644 --- a/Phaser/utils/DebugUtils.ts +++ b/Phaser/utils/DebugUtils.ts @@ -163,7 +163,7 @@ module Phaser { start(pointer.x, pointer.y - 100, color); line('ID: ' + pointer.id + " Active: " + pointer.active); - line('World X: ' + pointer.worldX() + " World Y: " + pointer.worldY()); + line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY); line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y); line('Duration: ' + pointer.duration + " ms"); @@ -196,9 +196,18 @@ module Phaser { static renderInputInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') { start(x, y, color); - line('Input'); + + if (game.input.camera) + { + line('Input - Camera: ' + game.input.camera.ID); + } + else + { + line('Input - Camera: null'); + } + line('X: ' + game.input.x + ' Y: ' + game.input.y); - line('World X: ' + game.input.getWorldX() + ' World Y: ' + game.input.getWorldY()); + line('World X: ' + game.input.worldX + ' World Y: ' + game.input.worldY); line('Scale X: ' + game.input.scale.x.toFixed(1) + ' Scale Y: ' + game.input.scale.x.toFixed(1)); line('Screen X: ' + game.input.activePointer.screenX + ' Screen Y: ' + game.input.activePointer.screenY); diff --git a/README.md b/README.md index 8ae9cc8e..9fad5749 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,10 @@ Latest Update TODO: -*** Render each camera to its own canvas - then I can apply filters (?), easily rotate it, scale it, etc without worrying about children * Default camera (camera 0) could be the stage camera, renders to stage? * Inject game into a
* Add ability to create extra
s within the game container, layered above/below the canvas -* One single canvas -* Inject Pixi.js into this fully? Use it for all rendering? A lot of work, but could be interesting? At least pixi is quite small. - +* Rename init to preload and call start automatically diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 8d6bd7e8..45c025bb 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -71,6 +71,10 @@ basic button.ts + + + camera buttons.ts + rotated buttons.ts diff --git a/Tests/buttons/camera buttons.js b/Tests/buttons/camera buttons.js new file mode 100644 index 00000000..ec1cc3fc --- /dev/null +++ b/Tests/buttons/camera buttons.js @@ -0,0 +1,26 @@ +/// +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render); + function init() { + game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); + game.load.start(); + } + var button; + var secondCam; + function create() { + button = game.add.button(100, 400, 'button', clickedIt, this, 2, 1, 0); + game.camera.width = 400; + //game.camera.rotation = 10; + game.camera.texture.opaque = true; + game.camera.texture.backgroundColor = 'rgb(100,0,0)'; + secondCam = game.add.camera(400, 0, 400, 600); + secondCam.texture.opaque = true; + secondCam.texture.backgroundColor = 'rgb(0,100,0)'; + } + function render() { + Phaser.DebugUtils.renderInputInfo(32, 32); + } + function clickedIt() { + } +})(); diff --git a/Tests/buttons/camera buttons.ts b/Tests/buttons/camera buttons.ts new file mode 100644 index 00000000..0f1788ff --- /dev/null +++ b/Tests/buttons/camera buttons.ts @@ -0,0 +1,44 @@ +/// +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render); + + function init() { + + game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); + game.load.start(); + + } + + var button: Phaser.UI.Button; + var secondCam: Phaser.Camera; + + function create() { + + button = game.add.button(100, 400, 'button', clickedIt, this, 2, 1, 0); + + game.camera.width = 400; + //game.camera.rotation = 10; + game.camera.texture.opaque = true; + game.camera.texture.backgroundColor = 'rgb(100,0,0)'; + + secondCam = game.add.camera(400, 0, 400, 600); + secondCam.texture.opaque = true; + secondCam.texture.backgroundColor = 'rgb(0,100,0)'; + + } + + function render() { + + Phaser.DebugUtils.renderInputInfo(32, 32); + + } + + function clickedIt() { + + + } + +})(); diff --git a/Tests/camera fx/mirror.js b/Tests/camera fx/mirror.js index 5f645858..a4ec965f 100644 --- a/Tests/camera fx/mirror.js +++ b/Tests/camera fx/mirror.js @@ -13,8 +13,6 @@ // What we need is a camera 800x400 pixels in size as the mirror effect will be 200px tall and sit below it. // So we resize our default camera to 400px game.camera.height = 400; - // Because it's our default camera we need to tell it to disable clipping, otherwise we'll never see the mirror effect render. - game.camera.disableClipping = true; // Add our effect to the camera mirror = game.camera.plugins.add(Phaser.Plugins.CameraFX.Mirror); // The first 2 parameters are the x and y coordinates of where to display the effect. They are in STAGE coordinates, not World. diff --git a/Tests/camera fx/mirror.ts b/Tests/camera fx/mirror.ts index 35e71452..c1a0ca0a 100644 --- a/Tests/camera fx/mirror.ts +++ b/Tests/camera fx/mirror.ts @@ -24,9 +24,6 @@ // So we resize our default camera to 400px game.camera.height = 400; - // Because it's our default camera we need to tell it to disable clipping, otherwise we'll never see the mirror effect render. - game.camera.disableClipping = true; - // Add our effect to the camera mirror = game.camera.plugins.add(Phaser.Plugins.CameraFX.Mirror); diff --git a/Tests/cameras/camera alpha.js b/Tests/cameras/camera alpha.js index cc60628b..24ef08aa 100644 --- a/Tests/cameras/camera alpha.js +++ b/Tests/cameras/camera alpha.js @@ -12,9 +12,9 @@ game.world.setSize(2240, 2240, true); game.add.sprite(0, 0, 'grid'); car = game.add.sprite(400, 300, 'car'); - game.camera.follow(car, Phaser.Phaser.Types.CAMERA_FOLLOW_TOPDOWN); + game.camera.follow(car, Phaser.Types.CAMERA_FOLLOW_TOPDOWN); miniCam = game.add.camera(0, 0, 300, 300); - miniCam.follow(car, Phaser.Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); + miniCam.follow(car, Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); miniCam.setBounds(0, 0, game.world.width, game.world.height); miniCam.texture.alpha = 0.7; } diff --git a/Tests/cameras/camera alpha.ts b/Tests/cameras/camera alpha.ts index f9d3700d..ce37b414 100644 --- a/Tests/cameras/camera alpha.ts +++ b/Tests/cameras/camera alpha.ts @@ -24,10 +24,10 @@ car = game.add.sprite(400, 300, 'car'); - game.camera.follow(car, Phaser.Phaser.Types.CAMERA_FOLLOW_TOPDOWN); + game.camera.follow(car, Phaser.Types.CAMERA_FOLLOW_TOPDOWN); miniCam = game.add.camera(0, 0, 300, 300); - miniCam.follow(car, Phaser.Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); + miniCam.follow(car, Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); miniCam.setBounds(0, 0, game.world.width, game.world.height); miniCam.texture.alpha = 0.7; diff --git a/Tests/cameras/follow styles.js b/Tests/cameras/follow styles.js index acafdf89..65ff5a7c 100644 --- a/Tests/cameras/follow styles.js +++ b/Tests/cameras/follow styles.js @@ -63,19 +63,19 @@ Phaser.DebugUtils.context.fillText('Current style: ' + style, 360, 48); } function lockonFollow() { - game.camera.follow(ufo, Phaser.Camera.STYLE_LOCKON); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_LOCKON); style = 'STYLE_LOCKON'; } function platformerFollow() { - game.camera.follow(ufo, Phaser.Camera.STYLE_PLATFORMER); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_PLATFORMER); style = 'STYLE_PLATFORMER'; } function topdownFollow() { - game.camera.follow(ufo, Phaser.Camera.STYLE_TOPDOWN); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_TOPDOWN); style = 'STYLE_TOPDOWN'; } function topdownTightFollow() { - game.camera.follow(ufo, Phaser.Camera.STYLE_TOPDOWN_TIGHT); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); style = 'STYLE_TOPDOWN_TIGHT'; } })(); diff --git a/Tests/cameras/follow styles.ts b/Tests/cameras/follow styles.ts index 89319b98..bd9df4d1 100644 --- a/Tests/cameras/follow styles.ts +++ b/Tests/cameras/follow styles.ts @@ -84,19 +84,19 @@ Phaser.DebugUtils.context.fillText('Current style: ' + style, 360, 48); } function lockonFollow() { - game.camera.follow(ufo, Phaser.Phaser.Types.CAMERA_FOLLOW_LOCKON); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_LOCKON); style = 'STYLE_LOCKON'; } function platformerFollow() { - game.camera.follow(ufo, Phaser.Phaser.Types.CAMERA_FOLLOW_PLATFORMER); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_PLATFORMER); style = 'STYLE_PLATFORMER'; } function topdownFollow() { - game.camera.follow(ufo, Phaser.Phaser.Types.CAMERA_FOLLOW_TOPDOWN); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_TOPDOWN); style = 'STYLE_TOPDOWN'; } function topdownTightFollow() { - game.camera.follow(ufo, Phaser.Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); + game.camera.follow(ufo, Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); style = 'STYLE_TOPDOWN_TIGHT'; } })(); diff --git a/Tests/mobile/sprite test 1.js b/Tests/mobile/sprite test 1.js index c5d6a7ef..633db779 100644 --- a/Tests/mobile/sprite test 1.js +++ b/Tests/mobile/sprite test 1.js @@ -26,8 +26,6 @@ emitter.makeParticles('jet', 50, false, 0); emitter.setRotation(0, 0); emitter.start(false, 10, 0.1); - // Make sure the camera doesn't clip anything - game.camera.disableClipping = true; game.stage.scale.enterLandscape.add(goneLandscape, this); game.stage.scale.enterPortrait.add(gonePortrait, this); game.onRenderCallback = render; diff --git a/Tests/mobile/sprite test 1.ts b/Tests/mobile/sprite test 1.ts index 55a38aef..8c852ef7 100644 --- a/Tests/mobile/sprite test 1.ts +++ b/Tests/mobile/sprite test 1.ts @@ -42,9 +42,6 @@ emitter.setRotation(0, 0); emitter.start(false, 10, 0.1); - // Make sure the camera doesn't clip anything - game.camera.disableClipping = true; - game.stage.scale.enterLandscape.add(goneLandscape, this); game.stage.scale.enterPortrait.add(gonePortrait, this); diff --git a/Tests/phaser.js b/Tests/phaser.js index b2e5af22..2dc3fdfc 100644 --- a/Tests/phaser.js +++ b/Tests/phaser.js @@ -2276,7 +2276,7 @@ var Phaser; if(this.enabled == false || this._parent.visible == false) { return false; } else { - return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY()); + return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY); } }; InputHandler.prototype.update = /** @@ -2290,7 +2290,7 @@ var Phaser; if(this.draggable && this._draggedPointerID == pointer.id) { return this.updateDrag(pointer); } else if(this._pointerData[pointer.id].isOver == true) { - if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY())) { + if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) { this._pointerData[pointer.id].x = pointer.x - this._parent.x; this._pointerData[pointer.id].y = pointer.y - this._parent.y; return true; @@ -2351,7 +2351,7 @@ var Phaser; this._pointerData[pointer.id].timeUp = this.game.time.now; this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown; // Only release the InputUp signal if the pointer is still over this sprite - if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY())) { + if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) { //console.log('releasedHandler: ' + Date.now()); this._parent.events.onInputUp.dispatch(this._parent, pointer); } else { @@ -2506,7 +2506,7 @@ var Phaser; this._draggedPointerID = pointer.id; this._pointerData[pointer.id].isDragged = true; if(this.dragFromCenter) { - this._parent.transform.centerOn(pointer.worldX(), pointer.worldY()); + this._parent.transform.centerOn(pointer.worldX, pointer.worldY); this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y); } else { this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y); @@ -9963,16 +9963,13 @@ var Phaser; * @param height {number} Height of the created camera. */ function CameraManager(game, x, y, width, height) { - /** - * Local helper stores index of next created camera. - */ - this._cameraInstance = 0; /** * Helper for sort. */ this._sortIndex = ''; this._game = game; this._cameras = []; + this._cameraLength = 0; this.defaultCamera = this.addCamera(x, y, width, height); this.current = this.defaultCamera; } @@ -10010,9 +10007,8 @@ var Phaser; * @returns {Camera} The newly created camera object. */ function (x, y, width, height) { - var newCam = new Phaser.Camera(this._game, this._cameraInstance, x, y, width, height); - this._cameras.push(newCam); - this._cameraInstance++; + var newCam = new Phaser.Camera(this._game, this._cameraLength, x, y, width, height); + this._cameraLength = this._cameras.push(newCam); return newCam; }; CameraManager.prototype.removeCamera = /** @@ -10046,6 +10042,16 @@ var Phaser; } return true; }; + CameraManager.prototype.getCameraUnderPoint = function (x, y) { + // Work through the cameras in reverse as they are rendered in array order + // Return the first camera we find matching the criteria + for(var c = this._cameraLength - 1; c >= 0; c--) { + if(this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) { + return this._cameras[c]; + } + } + return null; + }; CameraManager.prototype.sort = /** * Call this function to sort the Cameras according to a particular value and order (default is their Z value). * The order in which they are sorted determines the render order. If sorted on z then Cameras with a lower z-index value render first. @@ -12259,7 +12265,7 @@ var Phaser; */ function (layer) { if (typeof layer === "undefined") { layer = 0; } - return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.getWorldX(), this.game.input.getWorldY())]; + return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.worldX, this.game.input.worldY)]; }; Tilemap.prototype.getTileOverlaps = /** * Get tiles overlaps the given object. @@ -15682,6 +15688,13 @@ var Phaser; * @type {Any} **/ this.targetObject = null; + /** + * The top-most Camera that this Pointer is over (if any, null if none). + * If the Pointer is over several cameras that are stacked on-top of each other this is only ever set to the top-most rendered camera. + * @property camera + * @type {Phaser.Camera} + **/ + this.camera = null; this.game = game; this.id = id; this.active = false; @@ -15707,22 +15720,34 @@ var Phaser; enumerable: true, configurable: true }); - Pointer.prototype.worldX = /** - * Gets the X value of this Pointer in world coordinates based on the given camera. - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.input.camera; } - return camera.worldView.x + this.x; - }; - Pointer.prototype.worldY = /** - * Gets the Y value of this Pointer in world coordinates based on the given camera. - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.input.camera; } - return camera.worldView.y + this.y; - }; + Object.defineProperty(Pointer.prototype, "worldX", { + get: /** + * Gets the X value of this Pointer in world coordinates based on the given camera. + * @param {Camera} [camera] + */ + function () { + if(this.camera) { + return this.camera.worldView.x + this.x; + } + return null; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Pointer.prototype, "worldY", { + get: /** + * Gets the Y value of this Pointer in world coordinates based on the given camera. + * @param {Camera} [camera] + */ + function () { + if(this.camera) { + return this.camera.worldView.y + this.y; + } + return null; + }, + enumerable: true, + configurable: true + }); Pointer.prototype.start = /** * Called when the Pointer is pressed onto the touchscreen * @method start @@ -15790,6 +15815,8 @@ var Phaser; this._history.shift(); } } + // Check which camera they are over + this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y); } }; Pointer.prototype.move = /** @@ -16815,6 +16842,24 @@ var Phaser; this.recordLimit = 100; /** * A Pointer object + * @property pointer3 + * @type {Pointer} + **/ + this.pointer3 = null; + /** + * A Pointer object + * @property pointer4 + * @type {Pointer} + **/ + this.pointer4 = null; + /** + * A Pointer object + * @property pointer5 + * @type {Pointer} + **/ + this.pointer5 = null; + /** + * A Pointer object * @property pointer6 * @type {Pointer} **/ @@ -16856,9 +16901,6 @@ var Phaser; 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.pointer3 = new Phaser.Pointer(this.game, 3); - this.pointer4 = new Phaser.Pointer(this.game, 4); - this.pointer5 = new Phaser.Pointer(this.game, 5); this.mouse = new Phaser.Mouse(this.game); this.keyboard = new Phaser.Keyboard(this.game); this.touch = new Phaser.Touch(this.game); @@ -16873,7 +16915,6 @@ var Phaser; this.position = new Phaser.Vec2(); this._oldPosition = new Phaser.Vec2(); this.circle = new Phaser.Circle(0, 0, 44); - this.camera = this.game.camera; this.activePointer = this.mousePointer; this.currentPointers = 0; this.hitCanvas = document.createElement('canvas'); @@ -16884,6 +16925,20 @@ var Phaser; InputManager.MOUSE_OVERRIDES_TOUCH = 0; InputManager.TOUCH_OVERRIDES_MOUSE = 1; InputManager.MOUSE_TOUCH_COMBINE = 2; + Object.defineProperty(InputManager.prototype, "camera", { + get: /** + * The camera being used for mouse and touch based pointers to calculate their world coordinates. + * This is only ever the camera set by the most recently active Pointer. + * If you need to know exactly which camera a specific Pointer is over then see Pointer.camera instead. + * @property camera + * @type {Camera} + **/ + function () { + return this.activePointer.camera; + }, + enumerable: true, + configurable: true + }); Object.defineProperty(InputManager.prototype, "x", { get: /** * The X coordinate of the most recently active pointer. @@ -16895,7 +16950,7 @@ var Phaser; return this._x; }, set: function (value) { - this._x = Math.round(value); + this._x = Math.floor(value); }, enumerable: true, configurable: true @@ -16911,33 +16966,23 @@ var Phaser; return this._y; }, set: function (value) { - this._y = Math.round(value); + this._y = Math.floor(value); }, enumerable: true, configurable: true }); InputManager.prototype.addPointer = /** - * Add a new Pointer object to the Input Manager. By default Input creates 5 pointer objects for you. If you need more + * Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more * use this to create a new one, up to a maximum of 10. * @method addPointer * @return {Pointer} A reference to the new Pointer object **/ function () { var next = 0; - if(this.pointer10 === null) { - next = 10; - } - if(this.pointer9 === null) { - next = 9; - } - if(this.pointer8 === null) { - next = 8; - } - if(this.pointer7 === null) { - next = 7; - } - if(this.pointer6 === null) { - next = 6; + for(var i = 10; i > 0; i--) { + if(this['pointer' + i] === null) { + next = i; + } } if(next == 0) { throw new Error("You can only have 10 Pointer objects"); @@ -16998,9 +17043,15 @@ var Phaser; this.mousePointer.update(); this.pointer1.update(); this.pointer2.update(); - this.pointer3.update(); - this.pointer4.update(); - this.pointer5.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(); } @@ -17026,25 +17077,10 @@ var Phaser; if (typeof hard === "undefined") { hard = false; } this.keyboard.reset(); this.mousePointer.reset(); - this.pointer1.reset(); - this.pointer2.reset(); - this.pointer3.reset(); - this.pointer4.reset(); - this.pointer5.reset(); - if(this.pointer6) { - this.pointer6.reset(); - } - if(this.pointer7) { - this.pointer7.reset(); - } - if(this.pointer8) { - this.pointer8.reset(); - } - if(this.pointer9) { - this.pointer9.reset(); - } - if(this.pointer10) { - this.pointer10.reset(); + for(var i = 1; i <= 10; i++) { + if(this['pointer' + i]) { + this['pointer' + i].reset(); + } } this.currentPointers = 0; this.game.stage.canvas.style.cursor = "default"; @@ -17090,26 +17126,10 @@ var Phaser; **/ function () { this.currentPointers = 0; - if(this.pointer1.active == true) { - this.currentPointers++; - } else if(this.pointer2.active == true) { - this.currentPointers++; - } else if(this.pointer3.active == true) { - this.currentPointers++; - } else if(this.pointer4.active == true) { - this.currentPointers++; - } else if(this.pointer5.active == true) { - this.currentPointers++; - } else if(this.pointer6 && this.pointer6.active == true) { - this.currentPointers++; - } else if(this.pointer7 && this.pointer7.active == true) { - this.currentPointers++; - } else if(this.pointer8 && this.pointer8.active == true) { - this.currentPointers++; - } else if(this.pointer9 && this.pointer9.active == true) { - this.currentPointers++; - } else if(this.pointer10 && this.pointer10.active == true) { - this.currentPointers++; + for(var i = 1; i <= 10; i++) { + if(this['pointer' + i] && this['pointer' + i].active) { + this.currentPointers++; + } } return this.currentPointers; }, @@ -17131,22 +17151,12 @@ var Phaser; return this.pointer1.start(event); } else if(this.pointer2.active == false) { return this.pointer2.start(event); - } else if(this.pointer3.active == false) { - return this.pointer3.start(event); - } else if(this.pointer4.active == false) { - return this.pointer4.start(event); - } else if(this.pointer5.active == false) { - return this.pointer5.start(event); - } else if(this.pointer6 && this.pointer6.active == false) { - return this.pointer6.start(event); - } else if(this.pointer7 && this.pointer7.active == false) { - return this.pointer7.start(event); - } else if(this.pointer8 && this.pointer8.active == false) { - return this.pointer8.start(event); - } else if(this.pointer9 && this.pointer9.active == false) { - return this.pointer9.start(event); - } else if(this.pointer10 && this.pointer10.active == false) { - return this.pointer10.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; }; @@ -17158,26 +17168,16 @@ var Phaser; **/ function (event) { // Unrolled for speed - if(this.pointer1.active == true && this.pointer1.identifier == event.identifier) { + if(this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.move(event); - } else if(this.pointer2.active == true && this.pointer2.identifier == event.identifier) { + } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.move(event); - } else if(this.pointer3.active == true && this.pointer3.identifier == event.identifier) { - return this.pointer3.move(event); - } else if(this.pointer4.active == true && this.pointer4.identifier == event.identifier) { - return this.pointer4.move(event); - } else if(this.pointer5.active == true && this.pointer5.identifier == event.identifier) { - return this.pointer5.move(event); - } else if(this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier) { - return this.pointer6.move(event); - } else if(this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier) { - return this.pointer7.move(event); - } else if(this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier) { - return this.pointer8.move(event); - } else if(this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier) { - return this.pointer9.move(event); - } else if(this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier) { - return this.pointer10.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; }; @@ -17189,26 +17189,16 @@ var Phaser; **/ function (event) { // Unrolled for speed - if(this.pointer1.active == true && this.pointer1.identifier == event.identifier) { + if(this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.stop(event); - } else if(this.pointer2.active == true && this.pointer2.identifier == event.identifier) { + } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.stop(event); - } else if(this.pointer3.active == true && this.pointer3.identifier == event.identifier) { - return this.pointer3.stop(event); - } else if(this.pointer4.active == true && this.pointer4.identifier == event.identifier) { - return this.pointer4.stop(event); - } else if(this.pointer5.active == true && this.pointer5.identifier == event.identifier) { - return this.pointer5.stop(event); - } else if(this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier) { - return this.pointer6.stop(event); - } else if(this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier) { - return this.pointer7.stop(event); - } else if(this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier) { - return this.pointer8.stop(event); - } else if(this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier) { - return this.pointer9.stop(event); - } else if(this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier) { - return this.pointer10.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; }; @@ -17225,22 +17215,12 @@ var Phaser; return this.pointer1; } else if(this.pointer2.active == state) { return this.pointer2; - } else if(this.pointer3.active == state) { - return this.pointer3; - } else if(this.pointer4.active == state) { - return this.pointer4; - } else if(this.pointer5.active == state) { - return this.pointer5; - } else if(this.pointer6 && this.pointer6.active == state) { - return this.pointer6; - } else if(this.pointer7 && this.pointer7.active == state) { - return this.pointer7; - } else if(this.pointer8 && this.pointer8.active == state) { - return this.pointer8; - } else if(this.pointer9 && this.pointer9.active == state) { - return this.pointer9; - } else if(this.pointer10 && this.pointer10.active == state) { - return this.pointer10; + } else { + for(var i = 3; i <= 10; i++) { + if(this['pointer' + i] && this['pointer' + i].active == state) { + return this['pointer' + i]; + } + } } return null; }; @@ -17256,39 +17236,35 @@ var Phaser; return this.pointer1; } else if(this.pointer2.identifier == identifier) { return this.pointer2; - } else if(this.pointer3.identifier == identifier) { - return this.pointer3; - } else if(this.pointer4.identifier == identifier) { - return this.pointer4; - } else if(this.pointer5.identifier == identifier) { - return this.pointer5; - } else if(this.pointer6 && this.pointer6.identifier == identifier) { - return this.pointer6; - } else if(this.pointer7 && this.pointer7.identifier == identifier) { - return this.pointer7; - } else if(this.pointer8 && this.pointer8.identifier == identifier) { - return this.pointer8; - } else if(this.pointer9 && this.pointer9.identifier == identifier) { - return this.pointer9; - } else if(this.pointer10 && this.pointer10.identifier == identifier) { - return this.pointer10; + } else { + for(var i = 3; i <= 10; i++) { + if(this['pointer' + i] && this['pointer' + i].identifier == identifier) { + return this['pointer' + i]; + } + } } return null; }; - InputManager.prototype.getWorldX = /** - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.camera; } - return camera.worldView.x + this.x; - }; - InputManager.prototype.getWorldY = /** - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.camera; } - return camera.worldView.y + this.y; - }; + Object.defineProperty(InputManager.prototype, "worldX", { + get: function () { + if(this.camera) { + return (this.camera.worldView.x - this.camera.screenView.x) + this.x; + } + return null; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(InputManager.prototype, "worldY", { + get: function () { + if(this.camera) { + return (this.camera.worldView.y - this.camera.screenView.y) + this.y; + } + return null; + }, + enumerable: true, + configurable: true + }); InputManager.prototype.getDistance = /** * Get the distance between two Pointer objects * @method getDistance @@ -18243,7 +18219,7 @@ var Phaser; // Render the text DebugUtils.start(pointer.x, pointer.y - 100, color); DebugUtils.line('ID: ' + pointer.id + " Active: " + pointer.active); - DebugUtils.line('World X: ' + pointer.worldX() + " World Y: " + pointer.worldY()); + DebugUtils.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY); DebugUtils.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y); DebugUtils.line('Duration: ' + pointer.duration + " ms"); }; @@ -18271,9 +18247,13 @@ var Phaser; function renderInputInfo(x, y, color) { if (typeof color === "undefined") { color = 'rgb(255,255,255)'; } DebugUtils.start(x, y, color); - DebugUtils.line('Input'); + if(DebugUtils.game.input.camera) { + DebugUtils.line('Input - Camera: ' + DebugUtils.game.input.camera.ID); + } else { + DebugUtils.line('Input - Camera: null'); + } DebugUtils.line('X: ' + DebugUtils.game.input.x + ' Y: ' + DebugUtils.game.input.y); - DebugUtils.line('World X: ' + DebugUtils.game.input.getWorldX() + ' World Y: ' + DebugUtils.game.input.getWorldY()); + DebugUtils.line('World X: ' + DebugUtils.game.input.worldX + ' World Y: ' + DebugUtils.game.input.worldY); DebugUtils.line('Scale X: ' + DebugUtils.game.input.scale.x.toFixed(1) + ' Scale Y: ' + DebugUtils.game.input.scale.x.toFixed(1)); DebugUtils.line('Screen X: ' + DebugUtils.game.input.activePointer.screenX + ' Screen Y: ' + DebugUtils.game.input.activePointer.screenY); }; diff --git a/build/phaser.d.ts b/build/phaser.d.ts index d1455747..9dcc39a0 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -5113,9 +5113,9 @@ module Phaser { */ private _cameras; /** - * Local helper stores index of next created camera. + * Local container for storing cameras array length. */ - private _cameraInstance; + private _cameraLength; /** * Helper for sort. */ @@ -5164,6 +5164,7 @@ module Phaser { */ public removeCamera(id: number): bool; public swap(camera1: Camera, camera2: Camera, sort?: bool): bool; + public getCameraUnderPoint(x: number, y: number): Camera; /** * Call this function to sort the Cameras according to a particular value and order (default is their Z value). * The order in which they are sorted determines the render order. If sorted on z then Cameras with a lower z-index value render first. @@ -8298,15 +8299,22 @@ module Phaser { **/ public targetObject; /** + * The top-most Camera that this Pointer is over (if any, null if none). + * If the Pointer is over several cameras that are stacked on-top of each other this is only ever set to the top-most rendered camera. + * @property camera + * @type {Phaser.Camera} + **/ + public camera: Camera; + /** * Gets the X value of this Pointer in world coordinates based on the given camera. * @param {Camera} [camera] */ - public worldX(camera?: Camera): number; + public worldX : number; /** * Gets the Y value of this Pointer in world coordinates based on the given camera. * @param {Camera} [camera] */ - public worldY(camera?: Camera): number; + public worldY : number; /** * Called when the Pointer is pressed onto the touchscreen * @method start @@ -8858,10 +8866,12 @@ module Phaser { static MOUSE_TOUCH_COMBINE: number; /** * The camera being used for mouse and touch based pointers to calculate their world coordinates. + * This is only ever the camera set by the most recently active Pointer. + * If you need to know exactly which camera a specific Pointer is over then see Pointer.camera instead. * @property camera * @type {Camera} **/ - public camera: Camera; + public camera : Camera; /** * Phaser.Mouse handler * @type {Mouse} @@ -9086,7 +9096,7 @@ module Phaser { **/ public y : number; /** - * Add a new Pointer object to the Input Manager. By default Input creates 5 pointer objects for you. If you need more + * Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more * use this to create a new one, up to a maximum of 10. * @method addPointer * @return {Pointer} A reference to the new Pointer object @@ -9166,14 +9176,8 @@ module Phaser { * @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier. **/ public getPointerFromIdentifier(identifier: number): Pointer; - /** - * @param {Camera} [camera] - */ - public getWorldX(camera?: Camera): number; - /** - * @param {Camera} [camera] - */ - public getWorldY(camera?: Camera): number; + public worldX : number; + public worldY : number; /** * Get the distance between two Pointer objects * @method getDistance diff --git a/build/phaser.js b/build/phaser.js index b2e5af22..2dc3fdfc 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -2276,7 +2276,7 @@ var Phaser; if(this.enabled == false || this._parent.visible == false) { return false; } else { - return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY()); + return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY); } }; InputHandler.prototype.update = /** @@ -2290,7 +2290,7 @@ var Phaser; if(this.draggable && this._draggedPointerID == pointer.id) { return this.updateDrag(pointer); } else if(this._pointerData[pointer.id].isOver == true) { - if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY())) { + if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) { this._pointerData[pointer.id].x = pointer.x - this._parent.x; this._pointerData[pointer.id].y = pointer.y - this._parent.y; return true; @@ -2351,7 +2351,7 @@ var Phaser; this._pointerData[pointer.id].timeUp = this.game.time.now; this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown; // Only release the InputUp signal if the pointer is still over this sprite - if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX(), pointer.worldY())) { + if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) { //console.log('releasedHandler: ' + Date.now()); this._parent.events.onInputUp.dispatch(this._parent, pointer); } else { @@ -2506,7 +2506,7 @@ var Phaser; this._draggedPointerID = pointer.id; this._pointerData[pointer.id].isDragged = true; if(this.dragFromCenter) { - this._parent.transform.centerOn(pointer.worldX(), pointer.worldY()); + this._parent.transform.centerOn(pointer.worldX, pointer.worldY); this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y); } else { this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y); @@ -9963,16 +9963,13 @@ var Phaser; * @param height {number} Height of the created camera. */ function CameraManager(game, x, y, width, height) { - /** - * Local helper stores index of next created camera. - */ - this._cameraInstance = 0; /** * Helper for sort. */ this._sortIndex = ''; this._game = game; this._cameras = []; + this._cameraLength = 0; this.defaultCamera = this.addCamera(x, y, width, height); this.current = this.defaultCamera; } @@ -10010,9 +10007,8 @@ var Phaser; * @returns {Camera} The newly created camera object. */ function (x, y, width, height) { - var newCam = new Phaser.Camera(this._game, this._cameraInstance, x, y, width, height); - this._cameras.push(newCam); - this._cameraInstance++; + var newCam = new Phaser.Camera(this._game, this._cameraLength, x, y, width, height); + this._cameraLength = this._cameras.push(newCam); return newCam; }; CameraManager.prototype.removeCamera = /** @@ -10046,6 +10042,16 @@ var Phaser; } return true; }; + CameraManager.prototype.getCameraUnderPoint = function (x, y) { + // Work through the cameras in reverse as they are rendered in array order + // Return the first camera we find matching the criteria + for(var c = this._cameraLength - 1; c >= 0; c--) { + if(this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) { + return this._cameras[c]; + } + } + return null; + }; CameraManager.prototype.sort = /** * Call this function to sort the Cameras according to a particular value and order (default is their Z value). * The order in which they are sorted determines the render order. If sorted on z then Cameras with a lower z-index value render first. @@ -12259,7 +12265,7 @@ var Phaser; */ function (layer) { if (typeof layer === "undefined") { layer = 0; } - return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.getWorldX(), this.game.input.getWorldY())]; + return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.worldX, this.game.input.worldY)]; }; Tilemap.prototype.getTileOverlaps = /** * Get tiles overlaps the given object. @@ -15682,6 +15688,13 @@ var Phaser; * @type {Any} **/ this.targetObject = null; + /** + * The top-most Camera that this Pointer is over (if any, null if none). + * If the Pointer is over several cameras that are stacked on-top of each other this is only ever set to the top-most rendered camera. + * @property camera + * @type {Phaser.Camera} + **/ + this.camera = null; this.game = game; this.id = id; this.active = false; @@ -15707,22 +15720,34 @@ var Phaser; enumerable: true, configurable: true }); - Pointer.prototype.worldX = /** - * Gets the X value of this Pointer in world coordinates based on the given camera. - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.input.camera; } - return camera.worldView.x + this.x; - }; - Pointer.prototype.worldY = /** - * Gets the Y value of this Pointer in world coordinates based on the given camera. - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.input.camera; } - return camera.worldView.y + this.y; - }; + Object.defineProperty(Pointer.prototype, "worldX", { + get: /** + * Gets the X value of this Pointer in world coordinates based on the given camera. + * @param {Camera} [camera] + */ + function () { + if(this.camera) { + return this.camera.worldView.x + this.x; + } + return null; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Pointer.prototype, "worldY", { + get: /** + * Gets the Y value of this Pointer in world coordinates based on the given camera. + * @param {Camera} [camera] + */ + function () { + if(this.camera) { + return this.camera.worldView.y + this.y; + } + return null; + }, + enumerable: true, + configurable: true + }); Pointer.prototype.start = /** * Called when the Pointer is pressed onto the touchscreen * @method start @@ -15790,6 +15815,8 @@ var Phaser; this._history.shift(); } } + // Check which camera they are over + this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y); } }; Pointer.prototype.move = /** @@ -16815,6 +16842,24 @@ var Phaser; this.recordLimit = 100; /** * A Pointer object + * @property pointer3 + * @type {Pointer} + **/ + this.pointer3 = null; + /** + * A Pointer object + * @property pointer4 + * @type {Pointer} + **/ + this.pointer4 = null; + /** + * A Pointer object + * @property pointer5 + * @type {Pointer} + **/ + this.pointer5 = null; + /** + * A Pointer object * @property pointer6 * @type {Pointer} **/ @@ -16856,9 +16901,6 @@ var Phaser; 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.pointer3 = new Phaser.Pointer(this.game, 3); - this.pointer4 = new Phaser.Pointer(this.game, 4); - this.pointer5 = new Phaser.Pointer(this.game, 5); this.mouse = new Phaser.Mouse(this.game); this.keyboard = new Phaser.Keyboard(this.game); this.touch = new Phaser.Touch(this.game); @@ -16873,7 +16915,6 @@ var Phaser; this.position = new Phaser.Vec2(); this._oldPosition = new Phaser.Vec2(); this.circle = new Phaser.Circle(0, 0, 44); - this.camera = this.game.camera; this.activePointer = this.mousePointer; this.currentPointers = 0; this.hitCanvas = document.createElement('canvas'); @@ -16884,6 +16925,20 @@ var Phaser; InputManager.MOUSE_OVERRIDES_TOUCH = 0; InputManager.TOUCH_OVERRIDES_MOUSE = 1; InputManager.MOUSE_TOUCH_COMBINE = 2; + Object.defineProperty(InputManager.prototype, "camera", { + get: /** + * The camera being used for mouse and touch based pointers to calculate their world coordinates. + * This is only ever the camera set by the most recently active Pointer. + * If you need to know exactly which camera a specific Pointer is over then see Pointer.camera instead. + * @property camera + * @type {Camera} + **/ + function () { + return this.activePointer.camera; + }, + enumerable: true, + configurable: true + }); Object.defineProperty(InputManager.prototype, "x", { get: /** * The X coordinate of the most recently active pointer. @@ -16895,7 +16950,7 @@ var Phaser; return this._x; }, set: function (value) { - this._x = Math.round(value); + this._x = Math.floor(value); }, enumerable: true, configurable: true @@ -16911,33 +16966,23 @@ var Phaser; return this._y; }, set: function (value) { - this._y = Math.round(value); + this._y = Math.floor(value); }, enumerable: true, configurable: true }); InputManager.prototype.addPointer = /** - * Add a new Pointer object to the Input Manager. By default Input creates 5 pointer objects for you. If you need more + * Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more * use this to create a new one, up to a maximum of 10. * @method addPointer * @return {Pointer} A reference to the new Pointer object **/ function () { var next = 0; - if(this.pointer10 === null) { - next = 10; - } - if(this.pointer9 === null) { - next = 9; - } - if(this.pointer8 === null) { - next = 8; - } - if(this.pointer7 === null) { - next = 7; - } - if(this.pointer6 === null) { - next = 6; + for(var i = 10; i > 0; i--) { + if(this['pointer' + i] === null) { + next = i; + } } if(next == 0) { throw new Error("You can only have 10 Pointer objects"); @@ -16998,9 +17043,15 @@ var Phaser; this.mousePointer.update(); this.pointer1.update(); this.pointer2.update(); - this.pointer3.update(); - this.pointer4.update(); - this.pointer5.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(); } @@ -17026,25 +17077,10 @@ var Phaser; if (typeof hard === "undefined") { hard = false; } this.keyboard.reset(); this.mousePointer.reset(); - this.pointer1.reset(); - this.pointer2.reset(); - this.pointer3.reset(); - this.pointer4.reset(); - this.pointer5.reset(); - if(this.pointer6) { - this.pointer6.reset(); - } - if(this.pointer7) { - this.pointer7.reset(); - } - if(this.pointer8) { - this.pointer8.reset(); - } - if(this.pointer9) { - this.pointer9.reset(); - } - if(this.pointer10) { - this.pointer10.reset(); + for(var i = 1; i <= 10; i++) { + if(this['pointer' + i]) { + this['pointer' + i].reset(); + } } this.currentPointers = 0; this.game.stage.canvas.style.cursor = "default"; @@ -17090,26 +17126,10 @@ var Phaser; **/ function () { this.currentPointers = 0; - if(this.pointer1.active == true) { - this.currentPointers++; - } else if(this.pointer2.active == true) { - this.currentPointers++; - } else if(this.pointer3.active == true) { - this.currentPointers++; - } else if(this.pointer4.active == true) { - this.currentPointers++; - } else if(this.pointer5.active == true) { - this.currentPointers++; - } else if(this.pointer6 && this.pointer6.active == true) { - this.currentPointers++; - } else if(this.pointer7 && this.pointer7.active == true) { - this.currentPointers++; - } else if(this.pointer8 && this.pointer8.active == true) { - this.currentPointers++; - } else if(this.pointer9 && this.pointer9.active == true) { - this.currentPointers++; - } else if(this.pointer10 && this.pointer10.active == true) { - this.currentPointers++; + for(var i = 1; i <= 10; i++) { + if(this['pointer' + i] && this['pointer' + i].active) { + this.currentPointers++; + } } return this.currentPointers; }, @@ -17131,22 +17151,12 @@ var Phaser; return this.pointer1.start(event); } else if(this.pointer2.active == false) { return this.pointer2.start(event); - } else if(this.pointer3.active == false) { - return this.pointer3.start(event); - } else if(this.pointer4.active == false) { - return this.pointer4.start(event); - } else if(this.pointer5.active == false) { - return this.pointer5.start(event); - } else if(this.pointer6 && this.pointer6.active == false) { - return this.pointer6.start(event); - } else if(this.pointer7 && this.pointer7.active == false) { - return this.pointer7.start(event); - } else if(this.pointer8 && this.pointer8.active == false) { - return this.pointer8.start(event); - } else if(this.pointer9 && this.pointer9.active == false) { - return this.pointer9.start(event); - } else if(this.pointer10 && this.pointer10.active == false) { - return this.pointer10.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; }; @@ -17158,26 +17168,16 @@ var Phaser; **/ function (event) { // Unrolled for speed - if(this.pointer1.active == true && this.pointer1.identifier == event.identifier) { + if(this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.move(event); - } else if(this.pointer2.active == true && this.pointer2.identifier == event.identifier) { + } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.move(event); - } else if(this.pointer3.active == true && this.pointer3.identifier == event.identifier) { - return this.pointer3.move(event); - } else if(this.pointer4.active == true && this.pointer4.identifier == event.identifier) { - return this.pointer4.move(event); - } else if(this.pointer5.active == true && this.pointer5.identifier == event.identifier) { - return this.pointer5.move(event); - } else if(this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier) { - return this.pointer6.move(event); - } else if(this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier) { - return this.pointer7.move(event); - } else if(this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier) { - return this.pointer8.move(event); - } else if(this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier) { - return this.pointer9.move(event); - } else if(this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier) { - return this.pointer10.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; }; @@ -17189,26 +17189,16 @@ var Phaser; **/ function (event) { // Unrolled for speed - if(this.pointer1.active == true && this.pointer1.identifier == event.identifier) { + if(this.pointer1.active && this.pointer1.identifier == event.identifier) { return this.pointer1.stop(event); - } else if(this.pointer2.active == true && this.pointer2.identifier == event.identifier) { + } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) { return this.pointer2.stop(event); - } else if(this.pointer3.active == true && this.pointer3.identifier == event.identifier) { - return this.pointer3.stop(event); - } else if(this.pointer4.active == true && this.pointer4.identifier == event.identifier) { - return this.pointer4.stop(event); - } else if(this.pointer5.active == true && this.pointer5.identifier == event.identifier) { - return this.pointer5.stop(event); - } else if(this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier) { - return this.pointer6.stop(event); - } else if(this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier) { - return this.pointer7.stop(event); - } else if(this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier) { - return this.pointer8.stop(event); - } else if(this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier) { - return this.pointer9.stop(event); - } else if(this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier) { - return this.pointer10.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; }; @@ -17225,22 +17215,12 @@ var Phaser; return this.pointer1; } else if(this.pointer2.active == state) { return this.pointer2; - } else if(this.pointer3.active == state) { - return this.pointer3; - } else if(this.pointer4.active == state) { - return this.pointer4; - } else if(this.pointer5.active == state) { - return this.pointer5; - } else if(this.pointer6 && this.pointer6.active == state) { - return this.pointer6; - } else if(this.pointer7 && this.pointer7.active == state) { - return this.pointer7; - } else if(this.pointer8 && this.pointer8.active == state) { - return this.pointer8; - } else if(this.pointer9 && this.pointer9.active == state) { - return this.pointer9; - } else if(this.pointer10 && this.pointer10.active == state) { - return this.pointer10; + } else { + for(var i = 3; i <= 10; i++) { + if(this['pointer' + i] && this['pointer' + i].active == state) { + return this['pointer' + i]; + } + } } return null; }; @@ -17256,39 +17236,35 @@ var Phaser; return this.pointer1; } else if(this.pointer2.identifier == identifier) { return this.pointer2; - } else if(this.pointer3.identifier == identifier) { - return this.pointer3; - } else if(this.pointer4.identifier == identifier) { - return this.pointer4; - } else if(this.pointer5.identifier == identifier) { - return this.pointer5; - } else if(this.pointer6 && this.pointer6.identifier == identifier) { - return this.pointer6; - } else if(this.pointer7 && this.pointer7.identifier == identifier) { - return this.pointer7; - } else if(this.pointer8 && this.pointer8.identifier == identifier) { - return this.pointer8; - } else if(this.pointer9 && this.pointer9.identifier == identifier) { - return this.pointer9; - } else if(this.pointer10 && this.pointer10.identifier == identifier) { - return this.pointer10; + } else { + for(var i = 3; i <= 10; i++) { + if(this['pointer' + i] && this['pointer' + i].identifier == identifier) { + return this['pointer' + i]; + } + } } return null; }; - InputManager.prototype.getWorldX = /** - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.camera; } - return camera.worldView.x + this.x; - }; - InputManager.prototype.getWorldY = /** - * @param {Camera} [camera] - */ - function (camera) { - if (typeof camera === "undefined") { camera = this.game.camera; } - return camera.worldView.y + this.y; - }; + Object.defineProperty(InputManager.prototype, "worldX", { + get: function () { + if(this.camera) { + return (this.camera.worldView.x - this.camera.screenView.x) + this.x; + } + return null; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(InputManager.prototype, "worldY", { + get: function () { + if(this.camera) { + return (this.camera.worldView.y - this.camera.screenView.y) + this.y; + } + return null; + }, + enumerable: true, + configurable: true + }); InputManager.prototype.getDistance = /** * Get the distance between two Pointer objects * @method getDistance @@ -18243,7 +18219,7 @@ var Phaser; // Render the text DebugUtils.start(pointer.x, pointer.y - 100, color); DebugUtils.line('ID: ' + pointer.id + " Active: " + pointer.active); - DebugUtils.line('World X: ' + pointer.worldX() + " World Y: " + pointer.worldY()); + DebugUtils.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY); DebugUtils.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y); DebugUtils.line('Duration: ' + pointer.duration + " ms"); }; @@ -18271,9 +18247,13 @@ var Phaser; function renderInputInfo(x, y, color) { if (typeof color === "undefined") { color = 'rgb(255,255,255)'; } DebugUtils.start(x, y, color); - DebugUtils.line('Input'); + if(DebugUtils.game.input.camera) { + DebugUtils.line('Input - Camera: ' + DebugUtils.game.input.camera.ID); + } else { + DebugUtils.line('Input - Camera: null'); + } DebugUtils.line('X: ' + DebugUtils.game.input.x + ' Y: ' + DebugUtils.game.input.y); - DebugUtils.line('World X: ' + DebugUtils.game.input.getWorldX() + ' World Y: ' + DebugUtils.game.input.getWorldY()); + DebugUtils.line('World X: ' + DebugUtils.game.input.worldX + ' World Y: ' + DebugUtils.game.input.worldY); DebugUtils.line('Scale X: ' + DebugUtils.game.input.scale.x.toFixed(1) + ' Scale Y: ' + DebugUtils.game.input.scale.x.toFixed(1)); DebugUtils.line('Screen X: ' + DebugUtils.game.input.activePointer.screenX + ' Screen Y: ' + DebugUtils.game.input.activePointer.screenY); };