-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneExample.py
More file actions
66 lines (57 loc) · 2.32 KB
/
SceneExample.py
File metadata and controls
66 lines (57 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# This is a Blank Scene
#
# This is a template for what a Scene should look like
#
import pygwidgets
import pyghelpers
class MyScene(pyghelpers.Scene): # Inherits from the Scene class in the pyghelpers file
def __init__(self, window):
"""
This method is called when the scene is created
Create and/or load any assets (images, buttons, sounds)
that you need for this scene
"""
self.window = window
# As a sample, let's create a button
self.navButton = pygwidgets.TextButton(self.window, (300, 230), 'Navigate')
def getSceneKey(self):
return 'Some string or CONSTANT that uniquely represents this scene'
def enter(self, data):
"""
This method is called whenever the scene changes to this scene.
'data' is a any information that is passed from the previous scene
Typical use is to pass in a dictionary, from which useful data can be extracted.
"""
pass
def handleInputs(self, events, keyPressedList):
"""
This method is called on every frame when an event happens
It is passed in a list of events and a list of keyboard keys that are down
Typical code is to loop through the events and handle any that you want to
This method MUST be included in every scene to override the one in Scene
"""
for event in events:
if self.navButton.handleEvent(event):
print('Clicked on the nav button - typically add a: self.goToScene("NewScene")')
def update(self):
"""
This method is called once per frame while the scene is active
Include in here, any code you want to execute every frame
"""
pass
def draw(self):
"""
This method is called on every frame
Include any code that you need to draw everything in the window
(Typical is to do a window fill or show a background image,
and draw buttons, fields, characters, etc.)
This method MUST be included in every scene to override the one in Scene
"""
self.navButton.draw()
def leave(self):
"""
This method is called once when your code has asked to move on to a new scene
It should return any data that this scene wants to pass on to the next scene
"""
pass