-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.lua
100 lines (80 loc) · 2.79 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
-----------------------------------------------------------------------------------------
--
-- menu.lua
--
-----------------------------------------------------------------------------------------
local storyboard = require("storyboard")
local scene = storyboard.newScene()
-- Include Corona's "widget" library
local widget = require "widget"
--------------------------------------------
-- Buttons
local playButton
-- Handle play button
local function onPlayButtonRelease()
-- Play the game
storyboard.gotoScene("game", "fade", 500)
return true
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- Display a background image
local background = display.newImageRect("Background.png", display.contentWidth, display.contentHeight)
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
-- Display the logo
local logo = display.newText("Settlement", 0, 0, native.systemFontBold, 60)
logo.anchorX = 0.5
logo.anchorY = 0.5
logo.x = display.contentWidth / 2
logo.y = (3 * display.contentHeight) / 8
-- Create a widget button to play the game
playButton = widget.newButton{
label="Play",
labelColor={default={0}, over={255}},
font=native.systemFontBold,
fontSize = 28,
defaultFile="Button.png",
overFile="ButtonPressed.png",
width=240, height=80,
onRelease=onPlayButtonRelease
}
playButton.anchorX = 0.5
playButton.anchorY = 0.5
playButton.x = display.contentWidth * 0.5
playButton.y = (display.contentHeight / 2) + 100
-- All display objects must be inserted into group
group:insert(background)
group:insert(logo)
group:insert(playButton)
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
if playButton then
playButton:removeSelf()
playButton = nil
end
end
-- "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