I want to make an actor that moves down and when it hits the bottom of the world, it spawns back up at the top. I have no idea how to make a code for this.
Please help.
Thanks.
if(getY() == getWorld().getHeight()-1)
{
setLocation(getX() , 0);
}
else
{
setLocation(getX() , getY() + speed);
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public void act()
{
setLocation(getX(), getY()+5);
if(getY() == getWorld().getHeight()-1)
{
setLocation(getX() , 0);
}
else
{
setLocation(getX() , getY());
}
}
}