Scene
Create containerized pyDraw programs and apply them to the Screen independently!
Initialization
import * from pydraw
class MyScene(Scene):
# 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
def start(self):
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
else:
self.some_shape.move(x=3)
def keyup(self, key):
if key == 'x':
self.to_set_later += self.to_set_later % 3
def mousedown(self, location):
print(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!
def run():
# as you can see, it's just like a normal pyDraw program!
running = True
fps = 30
while running:
self.some_shape.color(Color.random())
self.screen().update()
self.screen().sleep(1 / fps)Methods
Start
Run
Screen
Input Methods
Last updated