1 decade ago by Doug
Does anyone have a good example of using the mouse to control the movement of an entity? For instance, moving the player paddle with the mouse in the pong demo.
This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact
ig.input.initMouse()
(or bind one of the mouse buttons). After that, the current mouse position is available at ig.input.mouse.x
and ig.input.mouse.y
so you can use it to set the entities position in its update function:update: function() { // Center the Paddle on the mouse cursor this.pos.y = ig.input.mouse.y - this.size.y/2; this.parent(); }
update: function(){ if (ig.input.state('mouseLeft')) { ig.game.spawnEntity( FireGib, ig.input.mouse.x,ig.input.mouse.y ); }