improvement: add a way to start a scene after init

This commit is contained in:
Kazhnuz Klappsthul 2021-01-24 15:44:07 +01:00
parent d3350e3938
commit af6ceef38d
2 changed files with 28 additions and 12 deletions

View File

@ -43,6 +43,7 @@ function SceneManager:setScene(scene)
self:startTransition(scene)
else
self.currentScene = scene
self.currentScene:start()
self.currentScene.isActive = true
end
end
@ -73,12 +74,7 @@ end
function SceneManager:update(dt)
self.timers:update(dt)
if (self.currentScene ~= nil) then
self.currentScene:updateStart(dt)
self.currentScene:setKeys()
self.currentScene.menusystem:update(dt)
self.currentScene:updateWorld(dt)
self.currentScene:update(dt)
self.currentScene:updateEnd(dt)
self.currentScene:updateScene(dt)
end
end
@ -146,6 +142,7 @@ end
function SceneManager:timerResponse(timer)
if timer == "fadeOut" then
self.currentScene = self.transition.nextScene
self.currentScene:start()
self.currentScene:flushKeys(self.transition.duration / 2.5)
self.currentScene.isActive = false
core.screen:fadeOut(self.transition.duration / 2.5, self.transition.easeOut)
@ -162,11 +159,7 @@ end
function SceneManager:draw()
self.controller.screen:apply()
if (self.currentScene ~= nil) then
self.currentScene:drawStart()
self.currentScene:drawWorld()
self.currentScene:draw()
self.currentScene.menusystem:draw()
self.currentScene:drawEnd()
self.currentScene:drawScene()
end
self.controller.screen:cease()
end

View File

@ -32,7 +32,7 @@ local MenuSystem = require(cwd .. "menusystem")
-- INIT FUNCTIONS
-- Initialize and configure the scene
function Scene:new()
function Scene:new(args)
self.mouse = {}
self.mouse.x, self.mouse.y = core.screen:getMousePosition()
@ -45,11 +45,17 @@ function Scene:new()
self:flushKeys()
self.isActive = false
self.args = args
self:initWorld()
self:register()
end
function Scene:start()
-- Empty function
end
function Scene:register()
core.scenemanager:setScene(self)
end
@ -61,6 +67,15 @@ end
-- UPDATE FUNCTIONS
-- 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)
end
@ -115,6 +130,14 @@ end
-- DRAW FUNCTIONS
-- Draw the scene and its content
function Scene:drawScene()
self:drawStart()
self:drawWorld()
self:draw()
self.menusystem:draw()
self:drawEnd()
end
function Scene:drawStart()
end