cykod / Quintus

HTML5 Game Engine
http://html5quintus.com
GNU General Public License v2.0
1.41k stars 401 forks source link

Getting update to date mouse coordinates when mouse does not move #157

Closed DalinSeivewright closed 9 years ago

DalinSeivewright commented 9 years ago

I was playing around with rotating sprites to face the mouse coordinates, using the mouseControls function of Q.input.

The mouse coordinates are only updated on mouse move, which makes sense, however this causes issues if a sprite is moving and the mouse is not moving. Because the mouse coordinates are transformed into stage space the "mouse coordinates" will continue moving away from the sprite and the rotation of the sprite will continue rotating towards this point in the stage space instead of the actual on-screen mouses position.

I've only started looking at Quintus this weekend so correct me if I'm wrong, but I don't see any way to get the current mouse coordinates at any given time using the Quintus library. I think that the canvas mouse location should be stored along with the transformed mouse coordinates. This way we can get the current stage-world mouse coordinates by simply calling canvasToStageX and canvasToStageY when we need to.

Again, I may have missed something glaringly obvious.

cykod commented 9 years ago

If you activate mouse controls - you should just be able to access them via Q.inputs['mouseX'] and Q.inputs['mouseY]

https://github.com/cykod/Quintus/blob/master/lib/quintus_input.js#L533

DalinSeivewright commented 9 years ago

The mouseX and mouseY values can be accessed from anywhere Quintus is accessible from however, the values are only ever updated on mouseMove. Since they are converted to scene coordinates, the coordinates are fixed in the scene until the mouse is moved again.