improvement: add a way to start a scene after init
This commit is contained in:
parent
d3350e3938
commit
af6ceef38d
2 changed files with 28 additions and 12 deletions
|
@ -43,6 +43,7 @@ function SceneManager:setScene(scene)
|
||||||
self:startTransition(scene)
|
self:startTransition(scene)
|
||||||
else
|
else
|
||||||
self.currentScene = scene
|
self.currentScene = scene
|
||||||
|
self.currentScene:start()
|
||||||
self.currentScene.isActive = true
|
self.currentScene.isActive = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,12 +74,7 @@ end
|
||||||
function SceneManager:update(dt)
|
function SceneManager:update(dt)
|
||||||
self.timers:update(dt)
|
self.timers:update(dt)
|
||||||
if (self.currentScene ~= nil) then
|
if (self.currentScene ~= nil) then
|
||||||
self.currentScene:updateStart(dt)
|
self.currentScene:updateScene(dt)
|
||||||
self.currentScene:setKeys()
|
|
||||||
self.currentScene.menusystem:update(dt)
|
|
||||||
self.currentScene:updateWorld(dt)
|
|
||||||
self.currentScene:update(dt)
|
|
||||||
self.currentScene:updateEnd(dt)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,6 +142,7 @@ end
|
||||||
function SceneManager:timerResponse(timer)
|
function SceneManager:timerResponse(timer)
|
||||||
if timer == "fadeOut" then
|
if timer == "fadeOut" then
|
||||||
self.currentScene = self.transition.nextScene
|
self.currentScene = self.transition.nextScene
|
||||||
|
self.currentScene:start()
|
||||||
self.currentScene:flushKeys(self.transition.duration / 2.5)
|
self.currentScene:flushKeys(self.transition.duration / 2.5)
|
||||||
self.currentScene.isActive = false
|
self.currentScene.isActive = false
|
||||||
core.screen:fadeOut(self.transition.duration / 2.5, self.transition.easeOut)
|
core.screen:fadeOut(self.transition.duration / 2.5, self.transition.easeOut)
|
||||||
|
@ -162,11 +159,7 @@ end
|
||||||
function SceneManager:draw()
|
function SceneManager:draw()
|
||||||
self.controller.screen:apply()
|
self.controller.screen:apply()
|
||||||
if (self.currentScene ~= nil) then
|
if (self.currentScene ~= nil) then
|
||||||
self.currentScene:drawStart()
|
self.currentScene:drawScene()
|
||||||
self.currentScene:drawWorld()
|
|
||||||
self.currentScene:draw()
|
|
||||||
self.currentScene.menusystem:draw()
|
|
||||||
self.currentScene:drawEnd()
|
|
||||||
end
|
end
|
||||||
self.controller.screen:cease()
|
self.controller.screen:cease()
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ local MenuSystem = require(cwd .. "menusystem")
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize and configure the scene
|
-- Initialize and configure the scene
|
||||||
|
|
||||||
function Scene:new()
|
function Scene:new(args)
|
||||||
self.mouse = {}
|
self.mouse = {}
|
||||||
self.mouse.x, self.mouse.y = core.screen:getMousePosition()
|
self.mouse.x, self.mouse.y = core.screen:getMousePosition()
|
||||||
|
|
||||||
|
@ -45,11 +45,17 @@ function Scene:new()
|
||||||
self:flushKeys()
|
self:flushKeys()
|
||||||
self.isActive = false
|
self.isActive = false
|
||||||
|
|
||||||
|
self.args = args
|
||||||
|
|
||||||
self:initWorld()
|
self:initWorld()
|
||||||
|
|
||||||
self:register()
|
self:register()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Scene:start()
|
||||||
|
-- Empty function
|
||||||
|
end
|
||||||
|
|
||||||
function Scene:register()
|
function Scene:register()
|
||||||
core.scenemanager:setScene(self)
|
core.scenemanager:setScene(self)
|
||||||
end
|
end
|
||||||
|
@ -61,6 +67,15 @@ end
|
||||||
-- UPDATE FUNCTIONS
|
-- UPDATE FUNCTIONS
|
||||||
-- Handle stuff that happens every steps
|
-- Handle stuff that happens every steps
|
||||||
|
|
||||||
|
function Scene:updateScene(dt)
|
||||||
|
self:updateStart(dt)
|
||||||
|
self:setKeys()
|
||||||
|
self.menusystem:update(dt)
|
||||||
|
self:updateWorld(dt)
|
||||||
|
self:update(dt)
|
||||||
|
self:updateEnd(dt)
|
||||||
|
end
|
||||||
|
|
||||||
function Scene:updateStart(dt)
|
function Scene:updateStart(dt)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -115,6 +130,14 @@ end
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the scene and its content
|
-- Draw the scene and its content
|
||||||
|
|
||||||
|
function Scene:drawScene()
|
||||||
|
self:drawStart()
|
||||||
|
self:drawWorld()
|
||||||
|
self:draw()
|
||||||
|
self.menusystem:draw()
|
||||||
|
self:drawEnd()
|
||||||
|
end
|
||||||
|
|
||||||
function Scene:drawStart()
|
function Scene:drawStart()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue