Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- display.setStatusBar(display.HiddenStatusBar)
- local storyboard = require "storyboard"
- local scene = storyboard.newScene()
- require "sprite"
- ----------------------------
- -- Functions
- ----------------------------
- local function buttonTouch(event)
- local button = event.target
- local bounds = button.contentBounds
- if event.phase == "began" then
- button.currentFrame = 2
- display.getCurrentStage():setFocus(button, event.id)
- button.isFocused = true
- elseif button.isFocused then
- local isWithinBounds = bounds.xMin <= event.x and bounds.xMax >= event.x and bounds.yMin <= event.y and bounds.yMax >= event.y
- if event.phase == "moved" then
- if isWithinBounds then
- button.currentFrame = 2
- else
- button.currentFrame = 1
- end
- elseif event.phase == "ended" or event.phase == 'cancelled' then
- if event.phase == "ended" and isWithinBounds then
- if options.audio then
- audio.play(audioChange)
- end
- button.currentFrame = 1
- storyboard.gotoScene(button.targetScene, "slideLeft", 500)
- end
- button.currentFrame = 1
- display.getCurrentStage():setFocus(button, nil)
- button.isFocused = false
- end
- end
- end
- ----------------------------
- -- Storyboard
- ----------------------------
- function scene:createScene(event)
- local group = self.view
- if options.audio then
- audioBackground = audio.loadStream("audio/menu_background" .. storyboard.audioType)
- audio.play(audioBackground, {fadein = 1000, loops = -1})
- audioChange = audio.loadSound("audio/menu_change" .. storyboard.audioType)
- end
- local background = display.newImage(group, "visuals/menu_background.png", 0, 0)
- local buttonSheet = sprite.newSpriteSheet("visuals/menu_buttons.png", 405, 100)
- local button = {}
- button.Play = sprite.newSprite(sprite.newSpriteSet(buttonSheet, 1, 2))
- group:insert(button.Play)
- button.Play.targetScene = "maps.level1Scene"
- button.Play:addEventListener("touch", buttonTouch)
- button.Play:setReferencePoint(display.TopCenterReferencePoint)
- button.Play.x = display.contentWidth / 2
- button.Play.y = 340
- buttonOptions = sprite.newSprite(sprite.newSpriteSet(buttonSheet, 3, 2))
- group:insert(button.Options)
- button.Options.targetScene ="optionsScene"
- button.Options:addEventListener("touch", buttonTouch)
- button.Options:setReferencePoint(display.TopLeftReferencePoint)
- button.Options.x = 50
- button.Options.y = 490
- buttonCredits = sprite.newSprite(sprite.newSpriteSet(buttonSheet, 5, 2))
- group:insert(button.Credits)
- buttonCredits.targetScene = "creditsScene"
- buttonCredits:addEventListener("touch", buttonTouch)
- buttonCredits:setReferencePoint(display.TopLeftReferencePoint)
- buttonCredits.x = 505
- buttonCredits.y = 490
- end
- function scene:exitScene(event)
- if options.audio then
- audio.stop()
- audio.dispose(audioBackground)
- audio.dispose(audioChange)
- end
- storyboard.purgeScene("menuScene")
- end
- scene:addEventListener("createScene", scene)
- scene:addEventListener("exitScene", scene)
- return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement