5 ms·
Do these new technologies enable lower mouse-event latencies? I struggle with making even the simplest 2d apps in a canvas element, because they always end up
by maho 11y ago
Do these new technologies enable lower mouse-event latencies? I struggle with making even the simplest 2d apps in a canvas element, because they always end up feeling sluggish. This was and still is a major point where Flash beats HTML5.
- adrusi 11y agoYou don't want to use mouse events for games. You probably want to use window.getAnimationFrame and then just query cursor coordinates. The mouse move events have to be filtered to be less frequent to accommodate some of the limitations of the JavaScript concurrency model.
- blaisio 11y agoNeither of the APIs you mention exist. Maybe you mean requestAnimationFrame? That still doesn't solve the problem of getting the current mouse coordinates though. Currently, the only way to get them is through events like mousemove. Honestly, it would be wonderful if we had immediate mode APIs for everything instead of being forced to register event handlers, which will always lag at least 1 frame behind.
- adrusi 11y agoWhoops, yeah it's been a while since I worried about stuff like this in javascript. I guess what I remembered doing was keeping track of cursor position in a global, updated on every mousemove to simulate immediate mode in a requestAnimationFrame callback. But as you say, that retains all the disadvantages of event latency. requestAnimationFrame is designed for immediate mode rendering, so it should probably pass its callback some information about input states or offer some other way of getting that.