Konzept: Bildfrequenz

Konzept: Bildfrequenz#

You can set how often act() is called by configuring the attributes world.fps and world.speed.

  • world.fps defines the frame rate. Similar to a flipbook, where you turn the pages at a set speed, the frame rate defines how often the image is redrawn per second. world.fps has a default value of 60, meaning 60 frames are displayed per second.

  • Im Attribut world.frame wird der aktuelle Frame gespeichert. Die Frames seit Programmstart werden hochgezählt.

  • world.speed defines how often the program logic (e.g., act) is called per second. A value of 60 means that the act() method is called every 60th frame.

  import miniworlds 

  world = miniworlds.World()
  world.size = (120,210)

  @world.register
  def on_setup(self):
      world.fps = 1
      world.speed = 3
      
  @world.register
  def act(self):
      print(world.frame)

  world.run()

The program above has the output:

  3
  6
  9
  12
  15

It is counting up very slowly because exactly one frame per second is played, and every 3rd frame (i.e., every 3 seconds) the function act() is called.