Clock
- class arcade.clock.Clock(initial_elapsed: float = 0.0, initial_tick: int = 0, tick_speed: float = 1.0)[source]
Bases:
A time keeping class which provides a method for easily tracking the elapsed time, delta_time, and number of ticks.
Arcade provides a global clock which is automatically ticked by the window.
Coming post 3.0: you can add ‘sub-clocks’ to Arcade’s top level clock which will tick at the same time, and have cumulative tick_speeds. This allows you to slow down only certain elements rather than everything.
- Parameters:
initial_elapsed – The amount of time the clock should assume has already occurred. Defaults to 0.0
initial_tick – The number of ticks the clock should assume has already occurred. Defaults to 0.
tick_speed – A multiplier on how the ‘speed’ of time. i.e. a value of 0.5 means time elapsed half as fast for this clock. Defaults to 1.0.
- set_max_deltatime(max_deltatime: float | None = None)[source]
Set the maximum deltatime that the clock will allow. If a large dt is passed into the clock’s tick method it will be clamped. This will desync the game’s time with the real world elapsed time, but can help protect against lag-spikes, debugger pauses, and other pauses to the event loop. This impacts the ‘raw’ dt so it does not take the clock’s tick speed into account
- Parameters:
max_deltatime – The maximum number of seconds that a clock can have as it’s deltatime. If set to None the clock has no limit. Defaults to None.
- set_tick_speed(new_tick_speed: float)[source]
Set the speed of time for this clock.
- Parameters:
new_tick_speed – A multiplier on the ‘speed’ of time. i.e. a value of 0.5 means time elapsed half as fast for this clock.
- property speed: float
A modifier on the delta time that elapsed each tick.
Decreasing the speed will ‘slow down’ time for this clock Immutable in 3.0
- tick(delta_time: float)[source]
Update the clock with the time that has passed since the last tick.
- Parameters:
delta_time – The amount of time that has passed since the last tick.
- class arcade.clock.FixedClock(sibling: Clock, fixed_tick_rate: float = 0.016666666666666666)[source]
Bases:
Clock
A fixed clock which expects its delta_time to stay constant. If it doesn’t it will throw an error.
Arcade provides a global fixed clock which is automatically ticked every update
- Parameters:
sibling – The unfixed clock which this clock will sync with.
fixed_tick_rate – The fixed number of seconds that pass for this clock every tick. Defaults to
1.0 / 60.0
.