|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface BaseTimer
BaseTimer
interface is an interface for running a loop
constantly in a requested frame per second.
Common methods of how-to-use BaseTimer
:
public class TimerEngine implements BaseTimer { ..... public static void main(String[] args) { BaseTimer engine = new TimerEngine(...); // set the target frame-per-second engine.setFPS(50); // 50 fps // start the timer!! engine.startTimer(); // game loop while (true) { // sleep to achieve the target frame-per-second long elapsedTime = engine.sleep(); } // stop the timer engine.stopTimer(); } }
Method Summary | |
---|---|
int |
getCurrentFPS()
Returns timer current frame per second. |
int |
getFPS()
Returns the requested frame per second. |
long |
getTime()
Returns timer current time in milliseconds. |
boolean |
isRunning()
Returns whether the timer is currently running or not. |
void |
refresh()
Refreshs timer elapsed time. |
void |
setFPS(int fps)
Sets this timer target frame per second to specified frame per second. |
long |
sleep()
Sleeps for awhile to achieve requested frame per second and returns the elapsed time since last sleep. |
void |
startTimer()
Starts the timer, please set appropriate frame per second first before calling this method. |
void |
stopTimer()
Stops this timer. |
Method Detail |
---|
void startTimer()
getCurrentFPS()
,
getFPS()
void stopTimer()
long sleep()
To call this method, timer must be in running state.
startTimer()
,
getFPS()
long getTime()
void refresh()
boolean isRunning()
Timer is running when startTimer()
is called.
startTimer()
int getCurrentFPS()
Current frame per second is the actual frame per second the player machine could achieve.
Because of one and many things (ie: the incapability of the player machine), the current frame per second can be differ from the requested frame per second.
getFPS()
,
startTimer()
int getFPS()
Requested frame per second is the target frame per second to achieve
(the number set in setFPS(int)
method).
Because of one and many things (ie: the incapability of the player machine), a high requested frame per second may not always be achieved.
To get the actual fps see getCurrentFPS()
.
getCurrentFPS()
,
setFPS(int)
void setFPS(int fps)
This timer is ordered to run as fast as this frame per second, but the actual fps achieved is depending of the player machine ability.
fps
- requested frame per secondgetCurrentFPS()
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |