Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by empika

Hallo

Loving the engine so far but I'm having some issue when trying to match an entity's position to the mouse position. Ie, I am trying to make an entity move to where I click.

If I console.log the mouses position and the entity's position, they are completely different.

in entity's update:
console.log("Mouse: " + ig.input.mouse.x + " : " + ig.input.mouse.y);
console.log("Entity: " + this.pos.x + " : " + this.pos.y);

For example, if I click in the top left corner of my entity I get:
Mouse: 161 : 121.5
Entity: 96 : 80

I can't understand why this may be, I thought it may be a scaling issue but I am using the default
ig.main( '#canvas', MyGame, 60, 320, 240, 2 );
On a canvas that is 640x480, clicking in the corners gives me a mouse report of 320:240 which is correct. So why is the entity reporting funny x and y coordinates?

Any ideas what might be happening?

Thanks

1 decade ago by empika

Got it, I was positioning the screen to center on the Entity, so therefore needed to compensate for that:

console.log("Mouse: " + (ig.input.mouse.x + ig.game.screen.x) + " : " + (ig.input.mouse.y + ig.game.screen.y));

1 decade ago by fugufish

cool that you solve it!

btw, if you have a camera on your canvas (like eg for a 2d scroller like mario), remember to include that in your calcs

1 decade ago by York

I was struggling with this one as well. Thanks for posting your solution, really saved me a lot of trouble.
Page 1 of 1
« first « previous next › last »