Timer#
Timer-Klassen planen Aktionen die in späteren Frames ausgelöst werden.
API-Referenz#
Timer#
- class miniworlds.tools.timer.Timer(time)[Quellcode]#
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)
- act()[Quellcode]#
Hook method that is executed when the timer interval is reached.
Subclasses override this method with the action that should happen after the configured number of frames.
- tick()[Quellcode]#
Counts frames and calls
act()when the timer interval is reached.This method is called automatically once per frame by the world.
ActionTimer#
- class miniworlds.tools.timer.ActionTimer(time, method, arguments=None)[Quellcode]#
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.
- __init__(time, method, arguments=None)[Quellcode]#
- act()[Quellcode]#
Calls the stored method once and then unregisters the timer.
This is the behavior behind
@timerand one-shot delayed actions.
LoopActionTimer#
- class miniworlds.tools.timer.LoopActionTimer(time, method, arguments=None)[Quellcode]#
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)
- act()[Quellcode]#
Calls the stored method once and then unregisters the timer.
This is the behavior behind
@timerand one-shot delayed actions.