GTGE API

com.golden.gamedev.object
Class Timer

java.lang.Object
  extended by com.golden.gamedev.object.Timer
All Implemented Interfaces:
Serializable

public class Timer
extends Object
implements Serializable

Class to manage timing in GTGE Frame Work to create game independent of frame rate. Timer is usually used to create sprite behaviour, such as used in sprite animation.

Example how to use timer in conjunction with sprite in order to make the sprite do an action every 1 second :

 public class DummySprite extends Sprite {

     // 1000 ms = 1 sec
     Timer timer = new Timer(1000);

     public void update(long elapsedTime) {
       if (timer.action(elapsedTime)) {
         // do an action!! this always called every 1 second
       }
     }

   }

 }
 

See Also:
Serialized Form

Constructor Summary
Timer(int delay)
          Creates new Timer with specified delay time in milliseconds.
 
Method Summary
 boolean action(long elapsedTime)
          Returns true, if the timer delay time has been elapsed, thus the action need to be performed.
 long getCurrentTick()
          Returns timer current tick.
 long getDelay()
          Returns timer delay time in milliseconds.
 boolean isActive()
          Returns active state of this timer, inactive timer won't do any action.
 void refresh()
          Refreshs the timer counter (current tick).
 void setActive(boolean b)
          Sets active state of this timer, inactive timer won't do any action.
 void setCurrentTick(long tick)
          Sets timer current tick.
 void setDelay(long i)
          Sets timer delay time in milliseconds.
 void setEquals(Timer other)
          Makes this timer state equals with other timer, this include active state, delay time, and timer current tick.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timer

public Timer(int delay)
Creates new Timer with specified delay time in milliseconds.

Parameters:
delay - delay time in milliseconds.
Method Detail

action

public boolean action(long elapsedTime)
Returns true, if the timer delay time has been elapsed, thus the action need to be performed.

Parameters:
elapsedTime - time elapsed since last update

refresh

public void refresh()
Refreshs the timer counter (current tick).


setEquals

public void setEquals(Timer other)
Makes this timer state equals with other timer, this include active state, delay time, and timer current tick.


isActive

public boolean isActive()
Returns active state of this timer, inactive timer won't do any action.


setActive

public void setActive(boolean b)
Sets active state of this timer, inactive timer won't do any action.


getDelay

public long getDelay()
Returns timer delay time in milliseconds.


setDelay

public void setDelay(long i)
Sets timer delay time in milliseconds.


getCurrentTick

public long getCurrentTick()
Returns timer current tick.

If current tick is exceeded timer delay time, the action(elapsedTime) method will return true.


setCurrentTick

public void setCurrentTick(long tick)
Sets timer current tick.

If current tick is exceeded timer delay time, the action(elapsedTime) method will return true.


GTGE API

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