I have a problem with my timer. I have set a timer variable to 70 and after this time delay a new ball should be created. It works, but after a certain time there are too many balls. So I intend that after 200 balls are created, all balls except one should be deleted and all starts from beginning on.
I tried to solve the problem with a List that counts all the ball objects. But I don`t manage it ....
Thanks a lot!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Balls extends Actor
{
private int intervall = 70;
public void act()
{
this.move(4);
this.changingDirection();
this.controllingTimer();
}
public void changingDirection()
{
if(this.isAtEdge())
{
this.turn(180);
}
}
public void controllingTimer()
{
if(intervall > 1)
{
this.intervall--;
}
else
{
int x = Greenfoot.getRandomNumber(580);
int y = Greenfoot.getRandomNumber (380);
MyWorld mw = this.getWorldOfType(MyWorld.class);
mw.addObject(new Balls(), x, y);
intervall = 70;
}
}
}
