Noob Questions From Nickcropheliac: Delaying Spawn Time?

I’m wondering what class would be able to do this. Say for example we have a constantly respawning enemy, and when you kill it, it instantly comes back. How would we delay this? What class? As you can tell, I’m new to Java and I’m stumped as to what it could be.

you could take a timestamp of when you killed the enemy and add the spawn time to it.

Every frame you could check if the time has passed the timestamp.

This is the simplest way I could think of

Super simple solution if you want to make sure it stays in sync with your game loop;

int respawnTicker;
int respawnDelay = 1000; //or whatever you want to increase or decrease speed.
boolean isDead = false;

public void update(){
     if (isDead)
          respawnTicker++;
     if (respawnTicker > respawnDelay){
          respawnMethod();
          respawnTicker = 0;
     }
}

Then make sure you set isDead to true where ever the code is you “kill” it at.

The combination of Lion’s and Ray’s methods I posted a while ago: http://www.java-gaming.org/topics/how-to-delay-somthing-without-stopping-the-gameloop/33752/msg/317647/view.html#msg317647

EDIT: you may want to think about synchronization when add()ing if you do so on the GUI thread but are reading on the game loop thread. Either that or look into PriorityBlockingQueue

You guys are all extremely helpful, thank you. If I had a boolean for running, and I put this in a while loop, it should work. ;D

Are you using the limited update method where you do it 60 times per second , just a while loop is going to go through it faster than you can blink. Otherwise it will work perfectly.

Can you give me an example of what that would look like?