public final class GameTime extends java.lang.Object implements EnvironmentLoadedListener
GameTime class provides temporal information that can be used to perform time based events.
The time provided by this class is measured in (game loop) ticks which is essentially an iteration of the game's main update loop.
Examples
A common use-case is to track the passed time since a certain event occurred (e.g. some action was performed by an Entity).
Another example is an environment that has a time limit.
UpdateLoop.getTickRate()| Modifier and Type | Method and Description |
|---|---|
void |
loaded(Environment environment)
This method is called after the environment was loaded.
|
long |
now()
Gets the current game time in ticks.
|
long |
since(long tick)
Calculates the delta time between the current game time and the specified
ticks in milliseconds.
|
long |
sinceEnvironmentLoad()
Get the time in milliseconds that has passed since the current environment was loaded.
|
long |
sinceGameStart()
Gets the time in milliseconds that has passed since the game has been started.
This uses the configured update rate to calculate the passed time from the specified ticks. |
long |
toMilliseconds(long ticks)
Converts the specified ticks to milliseconds using the game loop's update rate.
|
long |
toMilliseconds(long ticks,
int updateRate)
Converts the specified ticks to milliseconds using the specified update rate.
|
long |
toTicks(int milliseconds)
Converts the specified milliseconds to ticks using the game loop's update rate.
|
long |
toTicks(int milliseconds,
int updateRate)
Converts the specified milliseconds to ticks using the specified update rate.
|
public long now()
UpdateLoop.getTicks()public long since(long tick)
tick - The tick for which to calculate the delta time.now()public long sinceGameStart()
public long sinceEnvironmentLoad()
public long toMilliseconds(long ticks)
ticks - The ticks that will be converted to milliseconds.public long toMilliseconds(long ticks,
int updateRate)
ticks - The ticks that will be converted to milliseconds.updateRate - The updateRate that is used for the conversion.public long toTicks(int milliseconds)
milliseconds - The milliseconds that will be converted to ticks.public long toTicks(int milliseconds,
int updateRate)
milliseconds - The milliseconds that will be converted to ticks.updateRate - The updateRate that is used for the conversion.public void loaded(Environment environment)
EnvironmentLoadedListenerloaded in interface EnvironmentLoadedListenerenvironment - The environment that was loaded.