WorldView now takes camera placement into account, so Buttons now work across multiple camera set-ups.

This commit is contained in:
Richard Davey 2013-08-08 03:24:26 +01:00
parent a174bbc6b3
commit 04dcb29c88
11 changed files with 50 additions and 23 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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.

View file

@ -22,10 +22,10 @@ Latest Update
TODO:
* Default camera (camera 0) could be the stage camera, renders to stage?
* Inject game into a <div>
* Add ability to create extra <div>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

View file

@ -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;
}
})();

View file

@ -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;
}

View file

@ -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.

View file

@ -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);
}

View file

@ -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)
{

1
build/phaser.d.ts vendored
View file

@ -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.

View file

@ -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.