Package de.gurkenlabs.litiengine
Class GameTime
java.lang.Object
de.gurkenlabs.litiengine.GameTime
- All Implemented Interfaces:
EnvironmentLoadedListener
,java.util.EventListener
public final class GameTime
extends java.lang.Object
implements EnvironmentLoadedListener
The
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.
- See Also:
UpdateLoop.getTickRate()
Method Summary
Modifier and Type Method 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.
Method Details
now
public long now()Gets the current game time in ticks.- Returns:
- The current game time in ticks.
- See Also:
UpdateLoop.getTicks()
since
public long since(long tick)Calculates the delta time between the current game time and the specified ticks in milliseconds.- Parameters:
tick
- The tick for which to calculate the delta time.- Returns:
- The delta time in ms.
- See Also:
now()
sinceGameStart
public 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.- Returns:
- The time since the game has been started.
sinceEnvironmentLoad
public long sinceEnvironmentLoad()Get the time in milliseconds that has passed since the current environment was loaded.- Returns:
- The time since the current environment was loaded.
toMilliseconds
public long toMilliseconds(long ticks)Converts the specified ticks to milliseconds using the game loop's update rate.- Parameters:
ticks
- The ticks that will be converted to milliseconds.- Returns:
- The milliseconds that correspond to the specified ticks.
toMilliseconds
public long toMilliseconds(long ticks, int updateRate)Converts the specified ticks to milliseconds using the specified update rate.- Parameters:
ticks
- The ticks that will be converted to milliseconds.updateRate
- The updateRate that is used for the conversion.- Returns:
- The milliseconds that correspond to the specified ticks.
toTicks
public long toTicks(int milliseconds)Converts the specified milliseconds to ticks using the game loop's update rate.- Parameters:
milliseconds
- The milliseconds that will be converted to ticks.- Returns:
- The ticks that correspond to the specified milliseconds.
toTicks
public long toTicks(int milliseconds, int updateRate)Converts the specified milliseconds to ticks using the specified update rate.- Parameters:
milliseconds
- The milliseconds that will be converted to ticks.updateRate
- The updateRate that is used for the conversion.- Returns:
- The ticks that correspond to the specified milliseconds.
loaded
Description copied from interface:EnvironmentLoadedListener
This method is called after the environment was loaded.- Specified by:
loaded
in interfaceEnvironmentLoadedListener
- Parameters:
environment
- The environment that was loaded.