Hi
I have just started using the corona sdk and so far I really like what I’ve seen :).
I am a web developer and have been interested in developing a game for a long time. I have started putting a little scene manager together, I am new to lua and would like to know if I am heading in the right direction.
the idea is to have scenes with standard functions i.e. load,update,unload maybe listeners but haven’t worked out how that would work. then to add each scene to the scene manager so I can switch from one scene to another and handle the cleaning up. is this over kill?
here is my code
[lua]-- sceneMgr.lua
sceneMgr = {}
sceneMgr.__index = sceneMgr
function sceneMgr.create()
local sm = {}
setmetatable(sm,sceneMgr) – make scene handle lookup
sm.currentScene = 1
sm.scenes = {}
sm.debugtxt = display.newText( “sceneManager Loaded”, 0, 0, native.systemFont, 10 )
sm.tPrevious = system.getTimer()
sm.running = false
return sm
end
function sceneMgr:changeScene(newScene)
self.currentScene = newScene
end
function sceneMgr:addScene(scene)
self.debugtxt.text = ‘sceen added’
table.insert(self.scenes,scene)
end
function sceneMgr:load()
self.debugtxt.text = 'loaded called has ’ … #self.scenes
self.debugtxt:setTextColor( 255,0,0 )
if self.scenes[self.currentScene] ~= nil then
self.debugtxt.text = ‘scene found’
self.scenes[self.currentScene]:load()
else
self.debugtxt.text = ‘current scene is nil’
end
end
function sceneMgr:start()
local _update = function(event)
self:update(event)
end
self.debugtxt:setTextColor( 0,0,0 )
Runtime:addEventListener(“enterFrame”,_update)
end
function sceneMgr:update(event)
local tDelta = event.time - self.tPrevious
self.tPrevious = event.time
if self.scenes[self.currentScene] ~= nil then
self.scenes[self.currentScene]:update(tDelta)
end
end
function sceneMgr:unload()
– call unload on current scene
end
function sceneMgr:loadSelected(sceneIndex)
end
function sceneMgr:updateSelected(sceneIndex)
end
function sceneMgr:unloadSelected(sceneIndex)
end
– main.lua
local menu = {}
local mu = menu.create()
local sm = sceneMgr.create()
sm:addScene(mul)
sm:load()
sm:start()[/lua] [import]uid: 12378 topic_id: 4976 reply_id: 304976[/import]
