Timer#
Timer classes schedule actions in future frames.
API Reference#
Timer#
- class miniworlds.tools.timer.Timer(time)[source]#
Calls its
act()method once after time frames have elapsed.Subclass this and override
act()when you need custom timer logic. For most use-cases preferActionTimeror the@timerdecorator.Public Methods:
__init__(time)tick()Counts frames and calls
act()when the timer interval is reached.act()Hook method that is executed when the timer interval is reached.
Inherited from
Timed__init__()tick()Advances the timer by one frame.
unregister()Removes the timer from the current world.
Private Methods:
_validate_interval(time)
ActionTimer#
- class miniworlds.tools.timer.ActionTimer(time, method, arguments=None)[source]#
Calls a method after time frames.
Example
Player moves after 48 frames:
miniworlds.ActionTimer(48, player.move, 2)
Same as above with decorator:
@miniworlds.timer(frames = 24) def moving(): player.move()
Public Methods:
__init__(time, method[, arguments])act()Calls the stored method once and then unregisters the timer.
Inherited from
TimerInherited from
Timed__init__()tick()Advances the timer by one frame.
unregister()Removes the timer from the current world.
LoopActionTimer#
- class miniworlds.tools.timer.LoopActionTimer(time, method, arguments=None)[source]#
Calls a method after time frames repeatedly until the timer is unregistered.
Example
Player moves after 48 frames:
miniworlds.LoopTimer(48, player.move, 2)
Same as above with decorator:
@miniworlds.loop(frames = 24) def moving(): player.move()
Public Methods:
act()Calls the stored method once and then unregisters the timer.
Inherited from
ActionTimerInherited from
TimerInherited from
Timed__init__()tick()Advances the timer by one frame.
unregister()Removes the timer from the current world.
Private Methods:
Inherited from
ActionTimer_call_method()Inherited from
Timer_validate_interval(time)