omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to use Scene.delay()?

    Pythonista
    3
    3
    1663
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • foresight
      foresight last edited by

      Hey Everyone,

      I'm making a game of snake (will post code later), and would like to slow down the drawing process. I've looked up scene.delay (which I don't know how to use properly) and also time.sleep. what is the best method and how do I implement it? Thanks!

      1 Reply Last reply Reply Quote 0
      • Sebastian
        Sebastian last edited by

        The delay function doesn't actually slow down the drawing process. It calls a given function after a certain amount of time. It kind of tells a function to wait for <i>n</i> seconds before it is called.

        Here's an example of the delay function:
        <pre>from scene import *

        class MyScene(Scene):
        def setup(self):
        self.color = (1,0,0)

        def change_color(self):
        	self.color = (0,1,0)
        	
        def draw(self):
        	background(*self.color)
        	self.delay(3, self.change_color)
        

        run(MyScene())</pre>

        This draws a <i>red</i> screen, and the delay function will change the color to <i>green</i> after 3 dt have passed.

        1 Reply Last reply Reply Quote 0
        • omz
          omz last edited by

          Another option to slow things down would be to pass the optional frame_interval parameter to the run function, like so: <pre>run(MyScene(), frame_interval=3)</pre>This would basically run the scene at 30 frames per second instead of 60 (passing 3 would be 20fps etc.).

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors