diff --git a/Phaser/input/InputHandler.ts b/Phaser/input/InputHandler.ts index 0e992acb..d2383305 100644 --- a/Phaser/input/InputHandler.ts +++ b/Phaser/input/InputHandler.ts @@ -336,8 +336,6 @@ module Phaser.Components { public _pointerOverHandler(pointer: Pointer) { - // { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, isDragged: false } - if (this._pointerData[pointer.id].isOver == false) { this._pointerData[pointer.id].isOver = true; diff --git a/Phaser/input/Pointer.ts b/Phaser/input/Pointer.ts index c71a7213..d6b85ac8 100644 --- a/Phaser/input/Pointer.ts +++ b/Phaser/input/Pointer.ts @@ -285,23 +285,28 @@ module Phaser { * Gets the X value of this Pointer in world coordinates based on the given camera. * @param {Camera} [camera] */ - public get worldX() { + public get worldX(): number { + if (this.camera) { - return this.camera.worldView.x + this.x; + return (this.camera.worldView.x - this.camera.screenView.x) + this.x; } + return null; + } /** * Gets the Y value of this Pointer in world coordinates based on the given camera. * @param {Camera} [camera] */ - public get worldY() { + public get worldY(): number { + if (this.camera) { - return this.camera.worldView.y + this.y; + return (this.camera.worldView.y - this.camera.screenView.y) + this.y; } + return null; } diff --git a/Phaser/utils/DebugUtils.ts b/Phaser/utils/DebugUtils.ts index f02a45eb..38407da3 100644 --- a/Phaser/utils/DebugUtils.ts +++ b/Phaser/utils/DebugUtils.ts @@ -213,6 +213,15 @@ module Phaser { } + static renderSpriteWorldView(sprite: Sprite, x: number, y: number, color?: string = 'rgb(255,255,255)') { + + start(x, y, color); + line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')'); + line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y); + line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1)); + + } + /** * Render debug infos. (including name, bounds info, position and some other properties) * @param x {number} X position of the debug info to be rendered. diff --git a/README.md b/README.md index 9fad5749..0e9b95ae 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,10 @@ Latest Update TODO: -* 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 * Rename init to preload and call start automatically +* Poll the Input handlers less frequently (every other frame?) @@ -34,7 +34,6 @@ TODO: * Check that tween pausing works with the new performance.now * Game.Time should monitor pause duration * Investigate bug re: tilemap collision and animation frames -* Pointer.getWorldX(camera) needs to take camera scale into consideration * Add clip support + shape options to Texture Component. * Need to be able to set the current tilemap layer, then the getTileXY default layer uses that one if no other given * Sprite collision events @@ -54,7 +53,6 @@ TODO: * Pixel-perfect click check * Check Flash atlas export is supported * DynamicTexture.setPixel needs to be swapped for a proper pixel put, not the filledRect it currently is. -* Check pointer picking objects with multiple cameras (check camera first, then object???) V1.0.0 diff --git a/Tests/buttons/camera buttons.js b/Tests/buttons/camera buttons.js index ec1cc3fc..493704bd 100644 --- a/Tests/buttons/camera buttons.js +++ b/Tests/buttons/camera buttons.js @@ -9,9 +9,9 @@ var button; var secondCam; function create() { - button = game.add.button(100, 400, 'button', clickedIt, this, 2, 1, 0); + button = game.add.button(200, 400, 'button', clickedIt, this, 2, 1, 0); + button.origin.setTo(0.5, 0.5); 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); @@ -20,7 +20,9 @@ } function render() { Phaser.DebugUtils.renderInputInfo(32, 32); + Phaser.DebugUtils.renderSpriteWorldView(button, 32, 200); } function clickedIt() { + button.rotation += 10; } })(); diff --git a/Tests/buttons/camera buttons.ts b/Tests/buttons/camera buttons.ts index 0f1788ff..38018be6 100644 --- a/Tests/buttons/camera buttons.ts +++ b/Tests/buttons/camera buttons.ts @@ -17,10 +17,10 @@ function create() { - button = game.add.button(100, 400, 'button', clickedIt, this, 2, 1, 0); + button = game.add.button(200, 400, 'button', clickedIt, this, 2, 1, 0); + button.origin.setTo(0.5, 0.5); game.camera.width = 400; - //game.camera.rotation = 10; game.camera.texture.opaque = true; game.camera.texture.backgroundColor = 'rgb(100,0,0)'; @@ -33,11 +33,13 @@ function render() { Phaser.DebugUtils.renderInputInfo(32, 32); + Phaser.DebugUtils.renderSpriteWorldView(button, 32, 200); } function clickedIt() { + button.rotation += 10; } diff --git a/Tests/phaser.js b/Tests/phaser.js index 2dc3fdfc..c779dea5 100644 --- a/Tests/phaser.js +++ b/Tests/phaser.js @@ -2301,7 +2301,6 @@ var Phaser; } }; InputHandler.prototype._pointerOverHandler = function (pointer) { - // { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, isDragged: false } if(this._pointerData[pointer.id].isOver == false) { this._pointerData[pointer.id].isOver = true; this._pointerData[pointer.id].isOut = false; @@ -15727,7 +15726,7 @@ var Phaser; */ function () { if(this.camera) { - return this.camera.worldView.x + this.x; + return (this.camera.worldView.x - this.camera.screenView.x) + this.x; } return null; }, @@ -15741,7 +15740,7 @@ var Phaser; */ function () { if(this.camera) { - return this.camera.worldView.y + this.y; + return (this.camera.worldView.y - this.camera.screenView.y) + this.y; } return null; }, @@ -18257,6 +18256,13 @@ var Phaser; 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); }; + DebugUtils.renderSpriteWorldView = function renderSpriteWorldView(sprite, x, y, color) { + if (typeof color === "undefined") { color = 'rgb(255,255,255)'; } + DebugUtils.start(x, y, color); + DebugUtils.line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')'); + DebugUtils.line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y); + DebugUtils.line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1)); + }; DebugUtils.renderSpriteInfo = /** * Render debug infos. (including name, bounds info, position and some other properties) * @param x {number} X position of the debug info to be rendered. diff --git a/Tests/tilemaps/map draw.js b/Tests/tilemaps/map draw.js index 3627a5f7..bd875f4d 100644 --- a/Tests/tilemaps/map draw.js +++ b/Tests/tilemaps/map draw.js @@ -32,8 +32,8 @@ function update() { // Collide everything with the map //map.collide(); - marker.x = game.math.snapToFloor(game.input.getWorldX(), 16); - marker.y = game.math.snapToFloor(game.input.getWorldY(), 16); + marker.x = game.math.snapToFloor(game.input.worldX, 16); + marker.y = game.math.snapToFloor(game.input.worldY, 16); if(game.input.mousePointer.isDown) { map.putTile(marker.x, marker.y, 32); } diff --git a/Tests/tilemaps/map draw.ts b/Tests/tilemaps/map draw.ts index cd95cf93..b72bf218 100644 --- a/Tests/tilemaps/map draw.ts +++ b/Tests/tilemaps/map draw.ts @@ -47,8 +47,8 @@ // Collide everything with the map //map.collide(); - marker.x = game.math.snapToFloor(game.input.getWorldX(), 16); - marker.y = game.math.snapToFloor(game.input.getWorldY(), 16); + marker.x = game.math.snapToFloor(game.input.worldX, 16); + marker.y = game.math.snapToFloor(game.input.worldY, 16); if (game.input.mousePointer.isDown) { diff --git a/build/phaser.d.ts b/build/phaser.d.ts index 9dcc39a0..decd809b 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -9465,6 +9465,7 @@ module Phaser { * @param [color] {number} color of the debug info to be rendered. (format is css color string) */ static renderInputInfo(x: number, y: number, color?: string): void; + static renderSpriteWorldView(sprite: Sprite, x: number, y: number, color?: string): void; /** * Render debug infos. (including name, bounds info, position and some other properties) * @param x {number} X position of the debug info to be rendered. diff --git a/build/phaser.js b/build/phaser.js index 2dc3fdfc..c779dea5 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -2301,7 +2301,6 @@ var Phaser; } }; InputHandler.prototype._pointerOverHandler = function (pointer) { - // { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, isDragged: false } if(this._pointerData[pointer.id].isOver == false) { this._pointerData[pointer.id].isOver = true; this._pointerData[pointer.id].isOut = false; @@ -15727,7 +15726,7 @@ var Phaser; */ function () { if(this.camera) { - return this.camera.worldView.x + this.x; + return (this.camera.worldView.x - this.camera.screenView.x) + this.x; } return null; }, @@ -15741,7 +15740,7 @@ var Phaser; */ function () { if(this.camera) { - return this.camera.worldView.y + this.y; + return (this.camera.worldView.y - this.camera.screenView.y) + this.y; } return null; }, @@ -18257,6 +18256,13 @@ var Phaser; 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); }; + DebugUtils.renderSpriteWorldView = function renderSpriteWorldView(sprite, x, y, color) { + if (typeof color === "undefined") { color = 'rgb(255,255,255)'; } + DebugUtils.start(x, y, color); + DebugUtils.line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')'); + DebugUtils.line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y); + DebugUtils.line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1)); + }; DebugUtils.renderSpriteInfo = /** * Render debug infos. (including name, bounds info, position and some other properties) * @param x {number} X position of the debug info to be rendered.