I have an actor class named balloons and I am trying to make it to when it gets deleted form the world it'll respawn this is my run method where the balloons initially get spawned
This code is what deletes the balloons
public void run(){ int y = 0; balloons = Greenfoot.getRandomNumber(5); lives = "Lives: "+liv; scoreText = "Score: "+score; addObject(new Cannon(),100,720); for(int i =0;i<=balloons;i++){ y = Greenfoot.getRandomNumber(400)+300; addObject(new Balloon(randomClr(),"a"),1400,y); } }
if(isAtEdge(getX())==true){ MyWorld.liv--; MyWorld.updateLives(); MyWorld.balloons = 0; getWorld().showText(MyWorld.lives,100,50); getWorld().removeObjects(getWorld().getObjects(Balloon.class)); } if(Greenfoot.mouseClicked(this)){ MyWorld.score++; MyWorld.updateScore(); getWorld().showText(MyWorld.scoreText,1300,50); getWorld().removeObjects(getWorld().getObjects(Balloon.class)); }