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

2017/12/24

Need help with Location of an object

MetinPlays MetinPlays

2017/12/24

#
Hi everyone, my problem is that I want to set an Object back to the Location where it started when it reached the end of the World. It is moving from right to left and when it reaches the end it should start again to move from right to left. Can anyone help me?
danpost danpost

2017/12/24

#
MetinPlays wrote...
I want to set an Object back to the Location where it started when it reached the end of the World. It is moving from right to left and when it reaches the end it should start again to move from right to left.
The left-most x-coordinate value is zero and the right-most is one less than the number of cells in the width of the world .
if (getX() == 0) setLocation(getWorld().getWidth()-1, getY());
should work.
MetinPlays MetinPlays

2017/12/24

#
Do I have to change anything? When the object reached the most left value it doesn't go back to the most right value
MetinPlays MetinPlays

2017/12/24

#
Ok I've made it, thanks a lot!
You need to login to post a reply.