-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene3.lua
129 lines (100 loc) · 4.42 KB
/
scene3.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
-- scene3.lua
local storyboard = require("storyboard")
local movieclip = require("movieclip")
local scene = storyboard.newScene()
--------------------------------------------
-- forward declarations and other locals
local screenW, screenH = display.contentWidth, display.contentHeight
local halfW, halfH = display.contentWidth*0.5, display.contentHeight*0.5
local background, mediumPig, littlePig, bigPig
local firstOption, secondOption
local myAnim
local function onNextButtonTouch(self,event)
if (event.phase == "ended") then
print("Next Button Pressed")
end
return true
end
local function onBackButtonTouch(self,event)
if (event.phase == "ended") then
storyboard.gotoScene( "scene2", "slideRight", 350 )
print("Back Button Pressed")
end
return true
end
-----------------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
--
-- NOTE: Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
-----------------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene(event)
local group = self.view
-- display a background image
background = display.newImageRect("images/scene3/background_botones.png", display.contentWidth, display.contentHeight)
background:setReferencePoint(display.TopLeftReferencePoint)
background.x, background.y = 0,0
-- Adding Navigation Button
firstOption = display.newImageRect("images/scene3/boton_uno_pequeno.png",450,450)
firstOption:setReferencePoint(display.CenterReferencePoint)
firstOption.x, firstOption.y = halfW-250, halfH
secondOption = display.newImageRect("images/scene3/boton_dos_pequeno.png",450,450)
secondOption:setReferencePoint(display.CenterReferencePoint)
secondOption.x, secondOption.y = halfW+250, halfH
backButton = display.newImageRect("images/generic_scene/back_button_a.png",105,105)
backButton:setReferencePoint(display.CenterReferencePoint)
backButton.x, backButton.y = screenW-1205, screenH-150
-- all display objects must be inserted into group
group:insert(background)
group:insert(firstOption)
group:insert(secondOption)
group:insert(backButton)
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene(event)
local group = self.view
-- Purging last Scene
storyboard.purgeScene("scene2")
-- Narrator voice starts
narrationSpeech = audio.loadSound("sounds/third_scene.mp3")
-- play the speech on any available channel, for at most 30 seconds, and invoke a callback when the audio finishes playing
narrationChannel = audio.play( narrationSpeech, { duration=30000, onComplete=NarrationFinished } ) -- play the speech on any available channel, for at most 30 seconds, and invoke a callback when the audio finishes playing
backButton.touch = onBackButtonTouch
backButton:addEventListener("touch",backButton)
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
-- remove unused elements
audio.stop(narrationChannel)
backButton:removeEventListener("touch",backButton)
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
end
function NarrationFinished(event)
print("Narration Finished on channel", event.channel)
if event.completed then
print("Narration completed playback naturally")
else
print("Narration was stopped before completion")
end
end
-----------------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener("createScene",scene)
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener("enterScene",scene)
-- "exitScene" event is dispatched whenever before next scene's transition begins
scene:addEventListener("exitScene",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)
-----------------------------------------------------------------------------------------
return scene