How do you make image sprite not go beyond a certain coordinate?

I am making a game in which the sprite moves when the button is pressed. But I want it to not go beyond a certain coordinate.
I am attaching the code below
Pls suggest ways to rectify it.
Thank you

I also tried leaving the "then" blank but it doesn't seem to work

It is not clear what you want to do.

Where does "car" start ? (x,y)
At what value of x do you want to stop "car" ? (seems you want 2 options ??)
Often better to try using "<" or ">" instead of "="

You could put a small Ball at the target location, set the moving Sprite in motion towards the small Ball, and stop the Sprite then it collides with the Ball.

This is a tutorial about making a game using the CloudDB and a Canvas. Mountain Kingdom - a chat real time two player, two device game using the CloudDB and a Canvas The game pieces know where they are based on colored areas of the Canvas.

You could similarly use colored zones on your Canvas to restrict movement.

@TIMAI2 @ABG @SteveJG Thank you for your inputs.
So basically I have a track as the bg of my canvas and I don't want the car to move outside the track. And if touches the side edges of the track the car shouldn't move.
I found out the coordinate of X of the track and used that in the if condition. However, that doesn't seem to work.

See here:

I used a ball instead of a sprite, with origin at centre and radius 30. Test for condition before trying to move the ball/sprite.


1 Like

Thank you so much :)) @TIMAI2 It is working now.
I had to put the code for moving the car inside the if condition.