I made a game in a class, but I have a piece of code which should spawn the ground, under the character to make it look like it's moving but I'm not sure why the boolean is there if it only is true once. Can anyone please explain? Code snippet:
If you need the full game, tell me and I will post it. Thanks!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Ground here. * * @author (your name) * @version (a version number or a date) */ public class Ground extends Actor { boolean canCreate = true; public void act() { move(-4); if(getX() + getImage().getWidth()/2 < getWorld().getWidth() && canCreate == true) { World world = getWorld(); Ground ground = new Ground(); world.addObject(ground, getX()+getImage().getWidth() ,getY()); canCreate = false; } if (getX()+getImage().getWidth()/2 < 0){ getWorld().removeObject(this); } } }