java.lang.Object
com.github.hanyaeger.api.Timer
- Direct Known Subclasses:
EntitySpawner
,FadeInTimer
The abstract superclass of all timers that are available for both
YaegerScene
and YaegerEntity
. To add a Timer
the YaegerEntity
or YaegerScene
should implement
the interface TimerContainer
, after which the method TimerContainer.setupTimers()
should be
implemented to add the newly created timers through the method TimerContainer.addTimer(Timer)
.
Extend this class and implement the method onAnimationUpdate(long)
.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Return the interval in ms that is being used by thisTimer
.protected void
handle
(long now) Handle an update.boolean
isActive()
State whether thisTimer
is currently active.boolean
State whether thisTimer
has been marked as garbage.abstract void
onAnimationUpdate
(long timestamp) Implement this method, which will be called each animation update with the given interval.final void
pause()
Pause the timer, so it will no longer update with each animation.void
remove()
When this method is called, thisTimer
is set for removal.void
reset()
Reset thisTimer
to start from the beginning again.final void
resume()
Resume the timer, so it will start updating on each animation again.void
setIntervalInMs
(long intervalInMs) Set the interval in ms that should be used by thisTimer
.
-
Constructor Details
-
Timer
protected Timer(long intervalInMs) Create a new instance ofTimer
for the given interval in milliseconds.- Parameters:
intervalInMs
- the interval in milliseconds
-
-
Method Details
-
handle
protected void handle(long now) Handle an update. This method is called on each interval as passed to the constructor of thisTimer
.- Parameters:
now
- the current timestamp
-
pause
public final void pause()Pause the timer, so it will no longer update with each animation. -
resume
public final void resume()Resume the timer, so it will start updating on each animation again. -
remove
public void remove()When this method is called, thisTimer
is set for removal. This will be done in the next Game World Update. -
onAnimationUpdate
public abstract void onAnimationUpdate(long timestamp) Implement this method, which will be called each animation update with the given interval.- Parameters:
timestamp
- the timestamp of the current frame given in nanoseconds
-
isGarbage
public boolean isGarbage()State whether thisTimer
has been marked as garbage.- Returns:
- a boolean stating whether this
Timer
has been marked as garbage
-
isActive
public boolean isActive()State whether thisTimer
is currently active. When aTimer
is paused, it is no longer active.- Returns:
- a boolean stating whether this
Timer
is active
-
getIntervalInMs
public long getIntervalInMs()Return the interval in ms that is being used by thisTimer
.- Returns:
- the interval in ms as a
long
-
setIntervalInMs
public void setIntervalInMs(long intervalInMs) Set the interval in ms that should be used by thisTimer
.- Parameters:
intervalInMs
- the interval in ms as along
-
reset
public void reset()Reset thisTimer
to start from the beginning again.
-