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
+4 -2
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;
}
})();
+4 -2
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;
}
+9 -3
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.
+2 -2
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);
}
+2 -2
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)
{