Time Skipping

for(int i=0; i < ufoMissiles.length; i++) {
ufoMissiles[i].doDraw(g);
}

For above code, if I want to draw ufoMissiles[1] after 1 second of drawing ufoMissiles[0], which things that I should do? ???
Thanks for your reply!

The uber simple way would be as follows:

int n = ufoMissiles.length;
for(int i=0;i<n;i++) {
ufoMissilies[i].doDraw(g);
Thread.sleep(1000);
}

It depends on the way your implementing this but there’s another way using timer tasks…

You’d need to create a class extending a TimerTask and override its run method with something like the following:

public void run() {

ufoMissiles[counter++].doDraw(g);
if(counter > MAX_VALUE) counter = 0;

}

You would then create an instance of the TimerTask class and set it up so that it would call its run method once every 1000 milliseconds. There are various constructors for TimerTasks each providing a slightly different feature. e.g. running forever, running just for a specified peroid of time… Hope this helps.

Thanks for Mr ribot.
I tried to apply:
int n = ufoMissiles.length;
for(int i=0;i<n;i++) {
ufoMissilies[i].doDraw(g);
Thread.sleep(1000);
}
but it leads to the screen (all elements) hold a second and then run again.
Sorry, I may not provide very detailed information.
In my program, there is a paint method:
public void paint (Graphics g) {
// doing any drawing

for(int i=0; i < ufoMissiles.length; i++) {
ufoMissiles[i].doDraw(g);
}
}
And then my class implements Runnable method,
public void run() {

if(ufoMissileCount < ufoMissiles.length &&ufos[i].isDropBomb()) {
for(int j=0; j < ufoMissiles.length; j++) {
if(! ufoMissiles[j].isAlive()) {
ufoMissiles[j].setX(0);
ufoMissiles[j].setY(ufos[i].getY() + ufos[i].getHeight());
ufoMissiles[j].setAlive(true);
ufoMissileCount++;
break;
}
}
}

…}
So, when the condition is achieved, it will draw the ufoMissile, but the ufoMissiles are too closed when they are displayed, so I want to separate them so that they can be displayed one by one.
Thank you.

You should look at the code where you set that condition ufos[i].isDropBomb(). Each time a UFO drops a bomb, save in a private field (e.g. ‘long lastBombDropTime;’) the value of System.currentTimeMillis(). Then don’t let that UFO drop its next bomb until ‘System.currentTimeMillis() - lastBombDropTime > 1000’ (1000ms = 1 second).

I see~ Thanks for David!!