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 | - | Runtime:dispatchEvent{name='Options'; } -- something else also goes here
|
| 21 | + | Runtime:dispatchEvent{name='Options'; Music = {Volume=volume} }
|
| 22 | ||
| 23 | local function buttonTouch(event) | |
| 24 | local button = event.target | |
| 25 | local bounds = button.contentBounds | |
| 26 | if event.phase == "began" then | |
| 27 | button.currentFrame = 2 | |
| 28 | display.getCurrentStage():setFocus(button, event.id) | |
| 29 | button.isFocused = true | |
| 30 | elseif button.isFocused then | |
| 31 | local isWithinBounds = bounds.xMin <= event.x and bounds.xMax >= event.x and bounds.yMin <= event.y and bounds.yMax >= event.y | |
| 32 | if event.phase == "moved" then | |
| 33 | if isWithinBounds then | |
| 34 | button.currentFrame = 2 | |
| 35 | else | |
| 36 | button.currentFrame = 1 | |
| 37 | end | |
| 38 | elseif event.phase == "ended" or event.phase == 'cancelled' then | |
| 39 | if event.phase == "ended" and isWithinBounds then | |
| 40 | if options.audio then | |
| 41 | audio.play(audioChange) | |
| 42 | end | |
| 43 | button.currentFrame = 1 | |
| 44 | storyboard.gotoScene(button.targetScene, "slideRight", 500) | |
| 45 | end | |
| 46 | button.currentFrame = 1 | |
| 47 | display.getCurrentStage():setFocus(button, nil) | |
| 48 | button.isFocused = false | |
| 49 | end | |
| 50 | end | |
| 51 | end | |
| 52 | ||
| 53 | ---------------------------- | |
| 54 | -- Storyboard | |
| 55 | ---------------------------- | |
| 56 | ||
| 57 | function scene:createScene(event) | |
| 58 | local group = self.view | |
| 59 | if options.audio then | |
| 60 | audioChange = audio.loadSound("audio/menu_change" .. storyboard.audioType)
| |
| 61 | end | |
| 62 | local background = display.newImage(group, "visuals/options_background.png", 0, 0) | |
| 63 | local button = {}
| |
| 64 | button.ToggleSheet = sprite.newSpriteSheet("visuals/options_buttontoggle.png", 150, 80)
| |
| 65 | button.ToggleSet = sprite.newSpriteSet(button.ToggleSheet, 1, 2) | |
| 66 | button.ToggleAudio = sprite.newSprite(button.ToggleSet) | |
| 67 | if not options.audio then | |
| 68 | button.ToggleAudio.currentFrame = 2 | |
| 69 | end | |
| 70 | button.ToggleAudio:addEventListener("tap", buttonToggle)
| |
| 71 | button.ToggleAudio:setReferencePoint(display.TopLeftReferencePoint) | |
| 72 | button.ToggleAudio.x = 468 | |
| 73 | button.ToggleAudio.y = 50 | |
| 74 | group:insert(button.ToggleAudio) | |
| 75 | button.OptionsBackSheet = sprite.newSpriteSheet("visuals/menu_buttonback.png", 100, 100)
| |
| 76 | button.OptionsBackSet = sprite.newSpriteSet(button.OptionsBackSheet, 1, 2) | |
| 77 | button.OptionsBack = sprite.newSprite(button.OptionsBackSet) | |
| 78 | group:insert(button.OptionsBack) | |
| 79 | button.OptionsBack.targetScene = "menuScene" | |
| 80 | button.OptionsBack:addEventListener("touch", buttonTouch)
| |
| 81 | button.OptionsBack:setReferencePoint(display.TopLeftReferencePoint) | |
| 82 | button.OptionsBack.x = 30 | |
| 83 | button.OptionsBack.y = 510 | |
| 84 | end | |
| 85 | ||
| 86 | function scene:exitScene(event) | |
| 87 | if options.audio then | |
| 88 | audio.stop() | |
| 89 | audio.dispose(audioChange) | |
| 90 | end | |
| 91 | storyboard.purgeScene("optionsScene")
| |
| 92 | end | |
| 93 | ||
| 94 | scene:addEventListener("createScene", scene)
| |
| 95 | scene:addEventListener("exitScene", scene)
| |
| 96 | return scene |