This site requires JavaScript, please enable it in your browser!
Greenfoot back
Recorsi
Recorsi wrote ...

2017/1/26

How can i stop an actor moving half way into the edge.

Recorsi Recorsi

2017/1/26

#
hello, i made a moveable paddle that you can move to the left and right. but it moves half way into the edge. i tried it with turn(180) but that makes it go crazy. does anybody know how to stop it moving in the edge?
Recorsi Recorsi

2017/1/26

#
danpost danpost

2017/1/26

#
You just need a controlling 'if' statement:
// in pseudo-code
if (not (moving_speed+location_coordinate < half_image_size) && moving_left) move_left();
You will need something of that form for each edge you need to check on.
Super_Hippo Super_Hippo

2017/1/26

#
You could have something like this at the end of the act method:
int leftEdge= getImage().getWidth()/2;
int rightEdge = getWorld().getWidth() - leftEdge - 1;
if (getX() < leftEdge) setLocation(leftEdge, getY());
else if (getX() > rightEdge) setLocation(rightEdge, getY());
Recorsi Recorsi

2017/1/26

#
thanks :D
You need to login to post a reply.