- 3
Help Me!!!
How to do touch screen hold in js?
18 Answers
- 1
Удцдцддвщп Йдцлшаоплы it seems to work fine so far, I just would prefer to use requestAnimationFrame() method because it is better for animations
https://code.sololearn.com/W5RvLH3epm9p/?ref=app
+ 3
wow...solved?
here's my try, implementing right+left movements, using setInterval:
https://code.sololearn.com/WUuh9w7A6gF4/?ref=app
(you could hold left and right buttons at same time -- walk without moving, move as soon as one is released)
+ 1
Karak10 Thank you, my friend, now I understand everything.
0
you must implement it by yourself using touch events...
this code could help you to understand how this kind of events works:
https://code.sololearn.com/WO8wrPV40Fzn/?ref=app
0
visph I'm writing a game. I need to make the little man move while holding the right arrow. How do I do this? https://code.sololearn.com/WcenB4Yq25Tu/?ref=app
0
change ontouchevent by ontouchstart
0
visph I tried touchstart and touchend. But it doesn't work. The touch screen is not held.
0
with ontouchstart instead of ontouchevent, the sprite start walking (but doesn't move)
0
visph I need you to move and walk.
0
you must also implement ontouchmove: ontouchstart is only fired once...
however ontouchmove is only fired when touch is moving... you may better start a setInterval or requestAnimationFrame to update user.x and element position... wich you cancel with clearInterval or by checking a global var set to true at ontouchstart and false at ontouchend...
0
visph Could you show me this for example code, if you are not difficult to do it. I just don't fully understand your point.
0
Not now, but I have saved a copy of your code, and if I do not forgot I will see later if that doesn't take me too much time ;)
I guess that I could do it, but I don't want to make promise wich I will not keep ^^
0
visph thanks.
0
Удцдцддвщп Йдцлшаоплы you simple make a variable and set it to true when a touch starts and false when the touch ends or cancels. If you want to make sure the user has been holding the touch for 5 seconds or more you could use setTimout global method, and use clearTimeout to cancel the timeout if touch ends before the 5 seconds have passed.
0
Karak10 Am I doing everything right? If not correct me https://code.sololearn.com/WcenB4Yq25Tu/?ref=app
0
Karak10 In short, I made a variable that is tracked by the touchstart and touchend events. And it draws all setInterval, but here I'm not quite sure about the correct choice. I kind of have two options: requestAnimationFrame and the one above. I don't know which one is better or more correct.
0
Karak10 Why did you choose requestAnimationFrame instead of the same setInterval?
0
Удцдцддвщп Йдцлшаоплы
requestAnimationFrame produces higher quality animation completely eliminating flicker and shear that can happen when using setTimeout or setInterval, and reduce or completely remove frame skips.
Shear
is when a new canvas buffer is presented to the display buffer midway through the display scan resulting in a shear line caused by the mismatched animation positions.
Flicker
is caused when the canvas buffer is presented to the display buffer before the canvas has been fully rendered.
Frame skip
is caused when the time between rendering frames is not in precise sync with the display hardware. Every so many frames a frame will be skipped producing inconsistent animation.