Skip to main content
gamedev.net
🔒 Locked

[java] for the most inteligent ones :)

Started by sushi-one Nov 19, 2003 at 1:32 PM 5 replies 750+ views
Original Post
sushi-one
sushi-one
I have two problems with my SpaceInvader game made in java... 1: when I play the game from a oter site, I dont see the graphics exept the enemies 2: I dont get the getTime() from the Date class to work?? Hans-Petter
Hans-Petter Harveg
NuffSaid
NuffSaid
The really intelligent ones post more details and source code that will help others in finding the problems.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
sushi-one
sushi-one
well, in this case, my point was that I''m the stupid one, witch
this only proves.. hehe

anyway, the timer problem is my bigest one, here are how I do it:

---------------------------------------

Declare a Date variable, and two timer variables:

public Date timer = new Date();
public long startTime;
public long stopTime;

then, when I''m initializing, I get the startTime by writing startTime = timer.getTime();

at last I get the stopTime every frame and compare it against the startTime:

stopTime = timer.GetTime();
if( (stopTime-startTime) > delayTime ) {
currentFrame++;
}

---------------------------------------

This doesn''t do anything, shouldn''t it be right?

Hans-Petter
Hans-Petter Harveg
sushi-one
sushi-one
thanks! it worked

Hans-Petter
Hans-Petter Harveg
NuffSaid
NuffSaid
quote:
well, in this case, my point was that I''m the stupid one, witch
this only proves.. hehe


I should have added a to that post. I think I sounded pretty patronizing and elitist there. My apologies.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
snowmoon
snowmoon
You may just want to note that currentTimeMillis can be quote innacurate on some platforms ( windows ) so that it will only change every 50 ms ~ 18 times a second.

If you need more accuracy you have a few options.
1) Use a native library
2) Use Sun JDK 1.4.2 or better and a sun.* class ( will be stock java in 1.5 finally )
3) Use a terrible hack in 100% java that I wrote a while ago that cannot give you an exact time but approximates 30 ticks per second quite well.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.