Hello! I'm a little bit new to Greenfoot and Java in general, but I'm attempting to create a "Crossy Road-ish" game that involves trains. I'm trying to wrap them around the world, but every time my train has only gone half way to the right, it suddenly teleports back to the left. Is there any way for the train to disappear COMPLETELY to the right, pause for a while, AND THEN appear from the left to start the process again? I will leave my code for my train below, thank you!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Train extends Enemies { public void act() { move(4); int x = getX(); int y = getY(); int worldWidth = getWorld().getWidth() - 1; int worldHeight = getWorld().getHeight() - 1; if(x >= worldWidth) { setLocation(-1, y); } if(x <= 0) { setLocation(worldWidth - 1, y); } if(y > worldHeight) { setLocation(x, 1); if(y <= 0) { setLocation(0, worldHeight - 1); } } }