Create containerized pyDraw programs and apply them to the Screen independently!
You can get started with Scenes by creating a new class that extends the base Scene class from pyDraw:
import * from pydraw
# you should declare your variables outside of any of the methods (static!)
some_variable = 34
some_shape = None # set pyDraw objects or uninitiated variables to None
to_set_later = None
# now we can define a "start" method which will run when the scene is displayed
self.some_shape = Rectangle(self.screen(), 10, 10, 75, 50, Color('red'))
self.to_set_later = self.some_shape.width() / 2
# you can setup the Scene's input hooks by defining the methods in the class
def keydown(self, key):
if key == 'x':
self.to_set_later += 1
def keyup(self, key):
if key == 'x':
self.to_set_later += self.to_set_later % 3
def mousedown(self, location):
# you won't even need to call screen.listen(), it happens automatically!
# next up we setup a "run" method which happens after our input methods!
# as you can see, it's just like a normal pyDraw program!
running = True
fps = 30
self.screen().sleep(1 / fps)
Should instantiate your variables and prepare everything that the input hooks will use (unless you have checks in your hooks)
Should contain your actual loop and main program logic.
Get the Screen that the Scene is tied to! (can throw errors if methods are being called without being attached to a Screen)
Supports all the same input methods that any other pyDraw program supports:
mousedown| When the mouse is pressed or is held, this will be called
mouseup| When the mouse is released this is called
mousedrag| When the mouse is dragged, this is called anytime the mouse moves and is held.
mousemove| When the mouse moves, this method is called.
keydown| When a key is pressed or is currently being held, this is called
keyup| When a key is released this is called