Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Time Skipping  (Read 961 times)
0 Members and 1 Guest are viewing this topic.
Offline monopolyli

Senior Newbie




Java games rock!


« Posted 2005-03-06 14:46:47 »

for(int i=0; i < ufoMissiles.length; i++) {
ufoMissiles.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? Huh
Thanks for your reply!
Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #1 - Posted 2005-03-06 20:05:11 »

The uber simple way would be as follows:

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

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #2 - Posted 2005-03-06 20:15:02 »

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.

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline monopolyli

Senior Newbie




Java games rock!


« Reply #3 - Posted 2005-03-07 00:21:12 »

Thanks for Mr ribot.
I tried to apply:
int n = ufoMissiles.length;
for(int i=0;i<n;i++) {
 ufoMissilies.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.doDraw(g);
}
}
And then my class implements Runnable method,
public void run() {
.............
.............

if(ufoMissileCount < ufoMissiles.length &&ufos.isDropBomb()) {
for(int j=0; j < ufoMissiles.length; j++) {
if(! ufoMissiles[j].isAlive()) {
ufoMissiles[j].setX(0);
ufoMissiles[j].setY(ufos.getY() + ufos.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.


Offline davidaprice

Junior Member





« Reply #4 - Posted 2005-03-07 06:23:50 »

You should look at the code where you set that condition ufos.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).
Offline monopolyli

Senior Newbie




Java games rock!


« Reply #5 - Posted 2005-03-08 11:07:11 »

I see~ Thanks for David!!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (74 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (28 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!