SHOW:
|
|
- or go back to the newest paste.
1 | display.setStatusBar(display.HiddenStatusBar) | |
2 | local storyboard = require "storyboard" | |
3 | local scene = storyboard.newScene() | |
4 | local json = require ("json") | |
5 | ||
6 | local audioChange = nil | |
7 | ||
8 | ---------------------------- | |
9 | -- Functions | |
10 | ---------------------------- | |
11 | ||
12 | local function buttonToggle(event) | |
13 | local button = event.target | |
14 | button.currentFrame = 3 - button.currentFrame | |
15 | local volume | |
16 | if button.currentFrame == 2 then | |
17 | volume = 0 | |
18 | else | |
19 | volume = 1 | |
20 | end | |
21 | -- we do something here, but what? | |
22 | end | |
23 | ||
24 | local function buttonTouch(event) | |
25 | local button = event.target | |
26 | local bounds = button.contentBounds | |
27 | if event.phase == "began" then | |
28 | button.currentFrame = 2 | |
29 | display.getCurrentStage():setFocus(button, event.id) | |
30 | button.isFocused = true | |
31 | elseif button.isFocused then | |
32 | local isWithinBounds = bounds.xMin <= event.x and bounds.xMax >= event.x and bounds.yMin <= event.y and bounds.yMax >= event.y | |
33 | if event.phase == "moved" then | |
34 | if isWithinBounds then | |
35 | button.currentFrame = 2 | |
36 | else | |
37 | button.currentFrame = 1 | |
38 | end | |
39 | elseif event.phase == "ended" or event.phase == 'cancelled' then | |
40 | if event.phase == "ended" and isWithinBounds then | |
41 | if options.audio then | |
42 | audio.play(audioChange) | |
43 | end | |
44 | button.currentFrame = 1 | |
45 | storyboard.gotoScene(button.targetScene, "slideRight", 500) | |
46 | end | |
47 | button.currentFrame = 1 | |
48 | display.getCurrentStage():setFocus(button, nil) | |
49 | button.isFocused = false | |
50 | end | |
51 | end | |
52 | end | |
53 | ||
54 | ---------------------------- | |
55 | -- Storyboard | |
56 | ---------------------------- | |
57 | ||
58 | function scene:createScene(event) | |
59 | local group = self.view | |
60 | if options.audio then | |
61 | audioChange = audio.loadSound("audio/menu_change" .. storyboard.audioType) | |
62 | end | |
63 | local background = display.newImage(group, "visuals/options_background.png", 0, 0) | |
64 | local button = {} | |
65 | button.ToggleSheet = sprite.newSpriteSheet("visuals/options_buttontoggle.png", 150, 80) | |
66 | button.ToggleSet = sprite.newSpriteSet(button.ToggleSheet, 1, 2) | |
67 | button.ToggleAudio = sprite.newSprite(button.ToggleSet) | |
68 | if not options.audio then | |
69 | button.ToggleAudio.currentFrame = 2 | |
70 | end | |
71 | button.ToggleAudio:addEventListener("tap", buttonToggle) | |
72 | button.ToggleAudio:setReferencePoint(display.TopLeftReferencePoint) | |
73 | button.ToggleAudio.x = 468 | |
74 | button.ToggleAudio.y = 50 | |
75 | group:insert(button.ToggleAudio) | |
76 | button.OptionsBackSheet = sprite.newSpriteSheet("visuals/menu_buttonback.png", 100, 100) | |
77 | button.OptionsBackSet = sprite.newSpriteSet(button.OptionsBackSheet, 1, 2) | |
78 | button.OptionsBack = sprite.newSprite(button.OptionsBackSet) | |
79 | group:insert(button.OptionsBack) | |
80 | button.OptionsBack.targetScene = "menuScene" | |
81 | button.OptionsBack:addEventListener("touch", buttonTouch) | |
82 | button.OptionsBack:setReferencePoint(display.TopLeftReferencePoint) | |
83 | button.OptionsBack.x = 30 | |
84 | button.OptionsBack.y = 510 | |
85 | end | |
86 | ||
87 | function scene:exitScene(event) | |
88 | if options.audio then | |
89 | audio.stop() | |
90 | audio.dispose(audioChange) | |
91 | end | |
92 | storyboard.purgeScene("optionsScene") | |
93 | end | |
94 | ||
95 | scene:addEventListener("createScene", scene) | |
96 | scene:addEventListener("exitScene", scene) | |
97 | return scene |