Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] getting fps

Started by role Feb 16, 2003 at 2:06 AM 4 replies 300+ views
Original Post
role
role
hi all, how to write code to get current fps (frame per second) ?? i use thread on awt, not swing timer
cyrax256
cyrax256
You should have a pair of ints in your graphical engine:

int currentFPS;
int pastFPS;

Everytime your engine renders an image, you should increment currentFPS. Your run() method in the thread should be something like this:

public void run() {
pastFPS = currentFPS;
currentFPS = 0;
try {
Thread.sleep(1000);
} catch (InterruptedException e)
The screen should show pastFPS, of course

Hope this helps
cyrax256
cyrax256
A very similar solution, without the use of Thread... why the use of _ before every variable name?

Mac for productivity
Linux for development
Palm for mobility
Windows... for the Solitaire
TSwitch
TSwitch
quote:
Original post by cyrax256
why the use of _ before every variable name?


It''s a convention to mean that that variable is a member variable of a class declared outside of a method. So you can''t become confused as to where a variable is from. I guess.
Member of the Unban nes8bit or the White Rhino in my Basement Gets Sold to the Highest Bidder Association (UNWRBGSHBA - Not accepting new members.)Member of the I'm Glad Mithrandir Finally Found an Association that Accepts People with his Past History Association (IGMFFAAPPHA)

Topic Locked

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

Sign in to reply to this topic.