Hi, I have the following code and every 2 seconds their should be a new object, but after some time no new objects are created.
Could you please explain to me what causes that.
Here is the code of the actor classHere are the lines from the class RAINBOWPLANET
And finally the code of the UNICORN class:
The problem is especially after the re-location of the unicorn at the beginning of the world if it has reached an edge.
public class DIRT extends Actor
{
private int x;
private int y;
/**
* Act - do whatever the DIRT wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*
*
*
*/
public void act()
{
if(RAINBOWPLANET.currentTime>(RAINBOWPLANET.last_dirt+2)){
RAINBOWPLANET.last_dirt=RAINBOWPLANET.currentTime;
while(x<=UNICORN.xpos+200){
x = Greenfoot.getRandomNumber(UNICORN.xpos+300);
}
while(y<=UNICORN.ypos-10){
y = Greenfoot.getRandomNumber(UNICORN.ypos+50);
}
getWorld().addObject(new DIRT(), x,y);
}
}public static long last_dirt; // in the constructor of the class start_time=System.currentTimeMillis()/1000; last_dirt=start_time; currentTime=start_time
// in the act method xpos=getX(); ypos=getY();
