I am currently calculating the time between frames in my game an using that to update animation etc, but it isnt smooth and i thought it ould be much simpler and smoother if the frame rate was constant as then i could update everything by just 1 tick. Would this be done by using vsync set at say 60hx to give 60fps, but then what happens if you cant do a complete loop every time, do you skip rendering the frame if you calculate that there isnt enought time left? Is this possible with j2d?

Why not just a Timer object? You can put your game loop and rendering inside the actionListener for the Timer. It keeps a very constant rate of time, I've never had any issues with it. Do you know how to use one?

Why not just a Timer object? You can put your game loop and rendering inside the actionListener for the Timer. It keeps a very constant rate of time, I've never had any issues with it. Do you know how to use one?

but doesnt that mean all my code will be in the event handlign thread, wont that cause control problems? Anyway ive switched to lwjgl now, but id ont know how to do it in that either.What i would like to know is why some games (eg aliean flux) use this method and the advantagesw, disadvantages it gave them.

Disadvantages:* Won't cope with slower machines so well (workaround: provide 50% framerate option)* Endless arguments on forums from people who disagree (workaround: ignore them and carry on making games)

Can i cahnge the refresh rate in windowed mode in lwjgl, i set the display mode but when enabling vsync it is still at the old rate? Also i ust noticed how slow Display.setTitle(..) seems to be, removing a call to it every frame (to display the fps)gave my frame rate a boost from 120 to 140 (now i only change the title when the rounded fps has changed).

Yeah, Display.sync(int fps) will give you what you want. It synchronizes you to the specified frames per second almost perfectly. In measured fps, my program is almost always between 59 and 61 when I use the sync method. You could go as low as 30 fps for most games and people wouldn't even notice a difference.

Well, Display.sync(..) doesnt work on my system, neither does sync2() or sync3(), but i have now come up with a solution that lets me have a tick based game at any frame rate. It uses this class shown below:

//length of each interval, or tickprivatefloatinterval;//amount through interval at last checkprivatefloatamount;//time at last check, in millisprivatefloatlastCheck;//the timer has been startedprivatebooleanstarted;

publicTickTimer(floatinterval){this.interval = interval; }

/** *starts the timer going, should be called before using the timer */publicvoidstart(){lastCheck = FPSCounter.getTime();started = true; }

publicbooleanisStarted(){returnstarted; }

/** *returns the number of intervals that have passed since *this method was last called, or since start() was called */publicintgetNumIntervalsPassed() throwsIllegalStateException{//started already?if(!started)thrownewIllegalStateException("Timer must be started.");//floatnow = (Sys.getTime()*1000f) / (float)Sys.getTimerResolution();floatdelta = now - lastCheck;lastCheck = now;//floatnewAmount = amount+delta;intintervalCount = 0;//while(newAmount >= interval){newAmount -= interval;intervalCount++; }amount = newAmount;returnintervalCount; }}

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