-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.lua
220 lines (143 loc) · 6.55 KB
/
menu.lua
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
----------------------------------------------------------------------------------
-- Scene Name
-- Scene notes
---------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
----------------------------------------------------------------------------------
--
-- NOTE:
--
-- Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
---------------------------------------------------------------------------------
-- local forward references should go here --
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- CREATE display objects and add them to 'group' here.
-- Example use-case: Restore 'group' from previously saved state.
-----------------------------------------------------------------------------
-- Require the widget library
local widget = require( "widget" )
-- These are the functions triggered by the buttons
local button1Press = function( event )
storyboard.gotoScene("scene1")
end
local button2Press = function( event )
storyboard.gotoScene("scene2")
end
local button3Press = function( event )
storyboard.gotoScene("scene3")
end
local button1 = widget.newButton
{
defaultFile = "buttonRed.png",
overFile = "buttonRedOver.png",
label = "Scene 1",
emboss = true,
onPress = button1Press,
}
local button2 = widget.newButton
{
defaultFile = "buttonRed.png",
overFile = "buttonRedOver.png",
label = "Scene 2",
emboss = true,
onPress = button2Press,
}
local button3 = widget.newButton
{
defaultFile = "buttonRed.png",
overFile = "buttonRedOver.png",
label = "Scene 3",
emboss = true,
onPress = button3Press,
}
button1.x = 160; button1.y = 160
button2.x = 160; button2.y = 240
button3.x = 160; button3.y = 320
-- Add what you want to belong to this scene only
group:insert(button1)
group:insert(button2)
group:insert(button3)
end
-- Called BEFORE scene has moved onscreen:
function scene:willEnterScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- This event requires build 2012.782 or later.
-----------------------------------------------------------------------------
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
-----------------------------------------------------------------------------
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
-----------------------------------------------------------------------------
end
-- Called AFTER scene has finished moving offscreen:
function scene:didExitScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- This event requires build 2012.782 or later.
-----------------------------------------------------------------------------
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- INSERT code here (e.g. remove listeners, widgets, save state, etc.)
-----------------------------------------------------------------------------
end
-- Called if/when overlay scene is displayed via storyboard.showOverlay()
function scene:overlayBegan( event )
local group = self.view
local overlay_name = event.sceneName -- name of the overlay scene
-----------------------------------------------------------------------------
-- This event requires build 2012.797 or later.
-----------------------------------------------------------------------------
end
-- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
function scene:overlayEnded( event )
local group = self.view
local overlay_name = event.sceneName -- name of the overlay scene
-----------------------------------------------------------------------------
-- This event requires build 2012.797 or later.
-----------------------------------------------------------------------------
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "willEnterScene" event is dispatched before scene transition begins
scene:addEventListener( "willEnterScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "didExitScene" event is dispatched after scene has finished transitioning out
scene:addEventListener( "didExitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-- "overlayBegan" event is dispatched when an overlay scene is shown
scene:addEventListener( "overlayBegan", scene )
-- "overlayEnded" event is dispatched when an overlay scene is hidden/removed
scene:addEventListener( "overlayEnded", scene )
---------------------------------------------------------------------------------
return scene