I want to know how i can spawn one villain after another.
It would be nice if there was a cooldown of about 3 seconds.
// in world class private int spawnTimer; public void act() { spawnTimer = (spawnTimer+1)%180; if (spawnTimer == 0) addObject(new Villian(), 0, 0); // other act stuff, if any }
private Actor spawnTimerDisplay = new Actor(){}; private void updateSpawnTimerDisplay() { String caption = "Villian spawns in "+(3-spawnTimer/60)+" seconds"; // or "2-", if that suits you better GreenfootImage img = new GreenfootImage(caption, 28, Color.BLACK, new Color(0, 0, 0, 0)); spawnTimerDisplay.setImage(img); } public void act() { spawnTimer = (spawnTimer+1)%180; if (spawnTimer%60 == 0) updateSpawnTimerDisplay(); if (spawnTimer == 0) addObject(new Villian(), 0, 0); }
public class SimpleActor extends greenfoot.Actor {}
private Actor spawnTimerDisplay = new SimpleActor();
updateSpawnTimerDisplay();