0

I would like to know how to stop a pixel moving in a specific direction, is it possible?

My question is I'm trying to stop a pixel from moving a certain direction by recording the current position of the pixel, how can this be done? Any suggestions are welcome.

1st Aug 2024, 8:25 AM
Akash Mahato
Akash Mahato - avatar
5 Réponses
2nd Aug 2024, 10:42 AM
Bob_Li
Bob_Li - avatar
1st Aug 2024, 9:15 AM
Ausgrindtube
Ausgrindtube - avatar
1st Aug 2024, 11:18 AM
Akash Mahato
Akash Mahato - avatar
+ 1
Do you mean that when you hit the stop button, you want the square to stay still? Or when the square gets to the end of the container? The first one: You'd have to stop the animate variable from adding the position on. The second one: Before you update the move, check if the boundary has been "hit".
1st Aug 2024, 4:07 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
perhaps use clearInterval(animate) for the stop button? Btw, you can use the <button></button> element instead of input type button or submit
2nd Aug 2024, 2:26 AM
Bob_Li
Bob_Li - avatar