I've noticed that one reason for some sluggishness in my game is that the default HTML links only activate after mouse up events. Naturally, this is how most websites work.
However, I'd like to change this, since my game is very graphical, and in most games, events are on mousedown. Hence it creates a bad comparison between my game and others.
I'm doing some research, but does anyone know off the top of their heads how to change link clicks to mousedown rather than mouseup?
Eg, I guess is there any easy way to use javascript to prevent the default click event, then redefine the click event to fire on mousedown?
Comments
1. mousedown: the mouse button was depressed (pressed down)
2. mouseup: the mouse button was released
2. click: one mousedown and one mouseup in sequence was detected on the element.
Eg: http://indiegamemag.com/wp-content/uploads/2015/05/goblins_and_grottos_04.jpg
That game's the same thing of HTML in nw.js. I would never call that a webpage even though it has the same HTML structure of one. For one thing, it has a completely different control ui to a webpage, just like my game, which relies on both keyboard and mouse clicks.
But I'd prefer to focus on the question at hand? I'm a bit lost as to the point of that last post. There are valid reasons why I want to change clicks to activate on mousedown.
Anyway. The first thing that comes to mind would be to change the event used from "click" to "mousedown". That would be somewhat difficult in SugarCube v1, since event handler attachment points are scattered around. In SugarCube v2, virtually all clickables are, eventually, setup via its ariaClick() jQuery plugin method, so patching that to use "mousedown" instead of "click" would catch most things—I should probably make that configurable, if possible.
Alternatively, it should be possible to stop propagation of all normal user "click" events while firing your own "click" event on user "mousedown" events during the capture phase. For example:
So essentially I bind mousedown to an autoclick on any hover class, and the only hovers on screen will be where the mouse is.
I find the subsequent click on mouseup to not be an issue, as by the time that happens, the screen has already cleared.