I want (never laugh) to try to make the game Fruit Ninja for the web in html / css / javascript, how can I track the holding of the mouse (like on the touchscreen with my finger) on the object (preferably an example of code when the alert when holding over the div button pressed)
- And what the mousemove does not suit? - invincible
- not after all if in Warcraft, for example, you hover it over with a mouse, and the fighter himself will choose to play, after all, not in a rush !? - Rules
- And what the mousemove does not suit? // There are bombs in the game. You can escape from them by lifting your finger from the screen for a while, without wasting time on a “detour”. A lot of time is saved. - knes
- I have not played the game until that time. And in the question I meant that you can track the mouse click flag, which can be set when mousedown and removed when mouseup. But IMHO, if there are difficulties in such things, then it is unlikely that you will succeed in accomplishing your plans, but you can always try;) - invincible
4 answers
Look at any example of drag and drop of the interface , when the button is clamped, the onmousedown event occurs, then the processing is performed using the onmousemove event and when the drag object enters the desired area (the coordinates of the desired objects are compared), any function, even an alert, is called.
Pressing the button can be tracked by event.button details
Make a field div on it draw objects. And on the very field you are broadcasting event interceptors: onmousedown, onmousemove, onmouseup ...
If, when onmousemove, the mouse has passed through the object, then you call the function to destroy the object with an onmouseover event.
<div id="field"> <div id="im_fruit"></div> </div> <script> $("#field").mousedown(function(){ $("#im_fruit").bind("mouseover", fimction(){ alert("Im killed!!"); }); }).mouseup(function(){ $("#im_fruit").unbind("mouseover"); }); </script>
This is using jQuery.
Hang up on the body handler to find out which element you are on, and in order to find out if the button is clamped or not, use a flag once the button == false is released.