|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.object.Timer
public class Timer
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 } } } }
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 |
---|
public Timer(int delay)
Timer
with specified delay time in milliseconds.
delay
- delay time in milliseconds.Method Detail |
---|
public boolean action(long elapsedTime)
elapsedTime
- time elapsed since last updatepublic void refresh()
public void setEquals(Timer other)
public boolean isActive()
public void setActive(boolean b)
public long getDelay()
public void setDelay(long i)
public long getCurrentTick()
If current tick is exceeded timer delay time, the action(elapsedTime) method will return true.
public void setCurrentTick(long tick)
If current tick is exceeded timer delay time, the action(elapsedTime) method will return true.
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |