frezza Posted January 31, 2016 Share Posted January 31, 2016 Hi all, I've been looking for a way to reproduce 'mouseover' but with touch (like a 'touchover'). Basically what I wanted to do is to recognize whether the touch of the user, at some point, is over a sprite or not. It works fine with the mouse. I'm pretty new at programming and I did look on whether it has already been asked but I couldn't find the same question. Hope it's clear enough. Thanks in advance for the help! Quote Link to comment Share on other sites More sharing options...
nmiguelmoura Posted January 31, 2016 Share Posted January 31, 2016 Hi! You want to see some changes in the sprite when the user is touching it, or something like that, right? Why don't you use touchstart event at the beginning (when user touches the sprite) and touchend when the user finishes touching the sprite? Hope it helps... Quote Link to comment Share on other sites More sharing options...
JazzAceman Posted January 31, 2016 Share Posted January 31, 2016 You can use the "ontouchmove" event to receive the current coordinates of an active touch. Then you simply check whether this coordinates lays within the sprite's bounding box. Quote Link to comment Share on other sites More sharing options...
frezza Posted February 1, 2016 Author Share Posted February 1, 2016 Thanks both for the response. nmiguelmoura, as for the touchstart and touchend, it works fine if the user just click and release but the problem start when the user click and hold. If he does and moves away from the sprite then I cannot track whether the sprite is being touched or not. JazzAceman, I think I'll try your option. Again thanks both! Quote Link to comment Share on other sites More sharing options...
nmiguelmoura Posted February 1, 2016 Share Posted February 1, 2016 Hi again, Forgot to tell you but there is a touchendoutside event, to prevent the situation you mentioned, but JazzAceman's solution is good too. I would go my way if i had one or two sprites, and JazzAceman's way if i had several sprites, to avoid having too much events. Quote Link to comment Share on other sites More sharing options...
frezza Posted February 4, 2016 Author Share Posted February 4, 2016 Sorry, for the delay. I've ruled out touchendoutside since, if I've understood correctly, the user needs to release the click to be activated. Anyway I've managed getting the coordinates with the touchmove, combined with a hitTest function provided by one of the forum members. I'm sure it's not the most efective way, but it works. I've also thought of using "containsPoint" and "hitArea", but coudn't get it working. So thanks all for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.