Skip to content

Instantly share code, notes, and snippets.

@omidahourai
Last active December 10, 2015 10:38
Show Gist options
  • Save omidahourai/4422116 to your computer and use it in GitHub Desktop.
Save omidahourai/4422116 to your computer and use it in GitHub Desktop.
AndersT - Q&A
--main.lua
local storyboard = require('storyboard')
storyboard.gotoScene('SceneGame')
--SceneGame.lua
local Game = storyboard.newScene()
Game:addEventListener('createScene', Game)
function Game:createScene()
scene = self.view
local scene = scene
require('Classes.Hud')
end
Game:addEventListener('enterScene', Game)
function Game:enterScene(event)
local scene = self.view
scene:dispatchEvent({name='enterScene'})
end
--Hud.lua
local scene = scene
local Hud = display.newGroup(); scene.Hud = Hud
scene:insert(Hud) --insert on load (we want to minimize moving display objects around during runtime, because most things will be static in the display order; just load them in order).
--these classes insert themselves into Hud when they load
require('Classes.Hud.Health')
require('Classes.Hud.Score')
scene:addEventListener('enterScene', Hud)
function Hud:enterScene(event)
self:Show()
end
function Hud:Show()
self.isVisible = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment