lewster32 / phaser-plugin-isometric

Feature-packed axonometric plugin for Phaser 2 which stays true to the Phaser API.
http://rotates.org/phaser/iso
MIT License
472 stars 163 forks source link

World scaling wrong mouse iso position #34

Open lucap86 opened 8 years ago

lucap86 commented 8 years ago

Hi, I've the need to scale the camera (zoom-in/out). when i scale it the mouse isometric position is not correctly rescaled.

(try to scale http://rotates.org/phaser/iso/examples/interaction.htm camera as example).

how can i resolve this issue?

lucap86 commented 8 years ago

ok i've found a solution, in the game update

game.iso.unproject({ x: game.input.activePointer.position.x / game.camera.scale.x, y: game.input.activePointer.position.y / game.camera.scale.y }, game.cursorPos);

do you think that unproject should support camera scale?

lucap86 commented 8 years ago

Same thing happen when change camera x/y.

lucap86 commented 8 years ago

this is the fix that i've found:

in update function this.game.iso.unproject({ x: (this.game.input.activePointer.position.x + this.game.camera.x) / this.game.camera.scale.x, y: (this.game.input.activePointer.position.y + this.game.camera.y) / this.game.camera.scale.y }, this.game.cursorPos);

unproject function

var x = point.x - (this.game.world.x + this.game.camera.x) - (this.game.world.width * this.anchor.x);

var y = point.y - (this.game.world.y + this.game.camera.y) - (this.game.world.height * this.anchor.y) + z

another aproach may be put all into unproject function

var x = ((point.x + this.game.camera.x) / this.game.camera.scale.x) - (this.game.world.x + this.game.camera.x) - (this.game.world.width * this.anchor.x); var y = ((point.y + this.game.camera.y) / this.game.camera.scale.y) - (this.game.world.y + this.game.camera.y) - (this.game.world.height * this.anchor.y) + z;

wassname commented 8 years ago

Nice work! Making un/projection handle world scaling sounds like a great step forward, maybe make it a pull request?

lewster32 commented 8 years ago

It's an interesting case - project and unproject are meant to be low-level functions for performing basic isometric math on ambiguous coordinates; it doesn't and shouldn't care about scale, offset or anything else. I personally think that although this is a useful addition, it probably shouldn't be added to unproject but could be added elsewhere. Not entirely sure where though...

YuriBrunetto commented 8 years ago

@lucap86 that worked for me! thank you <3