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()?
-
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!
-
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.
-
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.).