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.

property delta_time: float

The amount of time that elapsed during the last tick

property dt: float

Alias to Clock.delta_time

property max_deltatime: float | None
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

property t: float

Alias to Clock.time

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.

property tick_count: int

Alias to Clock.ticks

property ticks: int

The number of ticks that have occurred for this clock.

ticks_since(tick: int) int[source]

Calculate the number of ticks that have occurred since the given tick.

Parameters:

tick – The tick to compare against.

property time: float

The total number of seconds that have elapsed for this clock

time_since(time: float) float[source]

Calculate the amount of time that has passed since the given time.

Parameters:

time – The time to compare against.

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.

property accumulated: float

The total number of seconds that have elapsed for this clock

property fraction: float

The fraction of a fixed tick that has passed since the last tick.

property rate: float

The fixed number of seconds that pass for this clock every tick.

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

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.