GTGE API

com.golden.gamedev.engine
Interface BaseTimer

All Known Implementing Classes:
SystemTimer

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

startTimer

void startTimer()
Starts the timer, please set appropriate frame per second first before calling this method.

See Also:
getCurrentFPS(), getFPS()

stopTimer

void stopTimer()
Stops this timer.


sleep

long sleep()
Sleeps for awhile to achieve requested frame per second and returns the elapsed time since last sleep.

To call this method, timer must be in running state.

Returns:
Elapsed time since last sleep.
See Also:
startTimer(), getFPS()

getTime

long getTime()
Returns timer current time in milliseconds.


refresh

void refresh()
Refreshs timer elapsed time.


isRunning

boolean isRunning()
Returns whether the timer is currently running or not.

Timer is running when startTimer() is called.

See Also:
startTimer()

getCurrentFPS

int getCurrentFPS()
Returns timer current frame per second.

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.

Returns:
Timer current frame per second.
See Also:
getFPS(), startTimer()

getFPS

int getFPS()
Returns the requested frame per second.

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().

Returns:
Requested frame per second.
See Also:
getCurrentFPS(), setFPS(int)

setFPS

void setFPS(int fps)
Sets this timer target frame per second to specified frame per second.

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.

Parameters:
fps - requested frame per second
See Also:
getCurrentFPS()

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id