Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

World scaling wrong mouse iso position #34

Open
lucap86 opened this issue Dec 5, 2015 · 6 comments
Open

World scaling wrong mouse iso position #34

lucap86 opened this issue Dec 5, 2015 · 6 comments

Comments

@lucap86
Copy link

lucap86 commented Dec 5, 2015

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
Copy link
Author

lucap86 commented Dec 5, 2015

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
Copy link
Author

lucap86 commented Dec 6, 2015

Same thing happen when change camera x/y.

@lucap86
Copy link
Author

lucap86 commented Dec 6, 2015

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
Copy link
Collaborator

wassname commented Dec 6, 2015

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

@lewster32
Copy link
Owner

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
Copy link

@lucap86 that worked for me! thank you <3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants