feat(scene): add *Start() and *End() functions.
Make the scene children able to add functions before or after everything.
This commit is contained in:
parent
5f5faddbd5
commit
055ae92eb9
3 changed files with 25 additions and 2 deletions
|
@ -58,10 +58,13 @@ function TestScene:mousepressed(x, y)
|
|||
end
|
||||
|
||||
|
||||
function TestScene:draw()
|
||||
function TestScene:drawStart()
|
||||
love.graphics.setColor(.4, 0, 0, 1)
|
||||
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
||||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
function TestScene:drawEnd()
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.print(math.floor(self.i) .. " ; " .. self.mouse.x .. ":" .. self.mouse.y .. ":" .. self.world:countActors(), 16, 16)
|
||||
|
||||
|
|
|
@ -59,10 +59,18 @@ end
|
|||
-- UPDATE FUNCTIONS
|
||||
-- Handle stuff that happens every steps
|
||||
|
||||
function Scene:updateStart(dt)
|
||||
|
||||
end
|
||||
|
||||
function Scene:update(dt)
|
||||
-- Empty function, is just here to avoid crash
|
||||
end
|
||||
|
||||
function Scene:updateEnd(dt)
|
||||
|
||||
end
|
||||
|
||||
function Scene:updateWorld(dt)
|
||||
if (self.world ~= nil) and (self.world.isActive) then
|
||||
self.world:update(dt)
|
||||
|
@ -105,10 +113,18 @@ end
|
|||
-- DRAW FUNCTIONS
|
||||
-- Draw the scene and its content
|
||||
|
||||
function Scene:drawStart()
|
||||
|
||||
end
|
||||
|
||||
function Scene:draw()
|
||||
|
||||
end
|
||||
|
||||
function Scene:drawEnd()
|
||||
|
||||
end
|
||||
|
||||
function Scene:drawWorld(dt)
|
||||
if (self.world ~= nil) then
|
||||
self.world:draw()
|
||||
|
|
|
@ -64,11 +64,13 @@ end
|
|||
|
||||
function SceneManager:update(dt)
|
||||
if (self.currentScene ~= nil) then
|
||||
self.currentScene:updateStart(dt)
|
||||
self.currentScene:setKeys()
|
||||
self.currentScene.assets:update(dt)
|
||||
self.currentScene.menusystem:update(dt)
|
||||
self.currentScene:updateWorld(dt)
|
||||
self.currentScene:update(dt)
|
||||
self.currentScene:updateEnd(dt)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -108,9 +110,11 @@ end
|
|||
function SceneManager:draw()
|
||||
self.controller.screen:apply()
|
||||
if (self.currentScene ~= nil) then
|
||||
self.currentScene:drawStart()
|
||||
self.currentScene:drawWorld()
|
||||
self.currentScene:draw(dt)
|
||||
self.currentScene:draw()
|
||||
self.currentScene.menusystem:draw()
|
||||
self.currentScene:drawEnd()
|
||||
end
|
||||
self.controller.screen:cease()
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue