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 prefer ActionTimer or the @timer decorator.

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 Timer

__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:

_call_method()

Inherited from Timer

_validate_interval(time)


__init__(time, method, arguments=None)[Quellcode]#
Parameter:
  • time (int) – After time frames, the method is called

  • method (callable) – The method to call.

  • arguments ([type], optional) – Arguments for the method.

act()[Quellcode]#

Calls the stored method once and then unregisters the timer.

This is the behavior behind @timer and 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 ActionTimer

__init__(time, method[, arguments])

act()

Calls the stored method once and then unregisters the timer.

Inherited from Timer

__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:

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 @timer and one-shot delayed actions.