rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
459 stars 50 forks source link

Mousemove with pointerlock is dropping events / delayed #40

Closed dekdevy closed 7 years ago

dekdevy commented 7 years ago

Hi,

there seems to be some problem with reporting mouse move events (particulary I am having this problem with pointerlock but i dont think it has anything to do with it.) I suspect this is because of the usage of Utils.throttle.

If I compare the event output to a raw document event hook, playground will effectively report less movement. This causes the reported movement to feel like its a bit sloppy and lagging behind what the mouse is actually doing. This behavior can also be seen in the pointerlock example with the flying spaceship. Its reacting well when you are moving the mouse slowly, but if you move the mouse quickly, it doesnt seem to speed up as much as it should.

Any fixes or ideas around this?

Edit: i fixed this for myself for now by removing the utils.throttle call on the mousemove event in the playground source.

rezoner commented 7 years ago

Yeah, throttling mouse move event is intentional as in games you rarely need high precision but often doing CPU heavy operations like looping through all entities to highlight what's under cursor etc.

I will provide some flag so you can check if you want the precision mouse or not.

dekdevy commented 7 years ago

cool! this will be very useful to get smooth FPS / egoshooter controls.

rezoner commented 7 years ago

Does this look ok?

var app = playground({
  mouseThrottling: false
});
dekdevy commented 7 years ago

Looks perfectly reasonable, thanks for the addition!

rezoner commented 7 years ago

Pushed the update.

Since you want to just disable the throttling it will not be useful for you but you can define the throttle in miliseconds like

var app = playground({
  mouseThrottling: 50    /* 20 times per second */
});