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
|
end
|
||||||
|
|
||||||
|
|
||||||
function TestScene:draw()
|
function TestScene:drawStart()
|
||||||
love.graphics.setColor(.4, 0, 0, 1)
|
love.graphics.setColor(.4, 0, 0, 1)
|
||||||
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
end
|
||||||
|
|
||||||
|
function TestScene:drawEnd()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
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)
|
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
|
-- UPDATE FUNCTIONS
|
||||||
-- Handle stuff that happens every steps
|
-- Handle stuff that happens every steps
|
||||||
|
|
||||||
|
function Scene:updateStart(dt)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function Scene:update(dt)
|
function Scene:update(dt)
|
||||||
-- Empty function, is just here to avoid crash
|
-- Empty function, is just here to avoid crash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Scene:updateEnd(dt)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function Scene:updateWorld(dt)
|
function Scene:updateWorld(dt)
|
||||||
if (self.world ~= nil) and (self.world.isActive) then
|
if (self.world ~= nil) and (self.world.isActive) then
|
||||||
self.world:update(dt)
|
self.world:update(dt)
|
||||||
|
@ -105,10 +113,18 @@ end
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the scene and its content
|
-- Draw the scene and its content
|
||||||
|
|
||||||
|
function Scene:drawStart()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function Scene:draw()
|
function Scene:draw()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Scene:drawEnd()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function Scene:drawWorld(dt)
|
function Scene:drawWorld(dt)
|
||||||
if (self.world ~= nil) then
|
if (self.world ~= nil) then
|
||||||
self.world:draw()
|
self.world:draw()
|
||||||
|
|
|
@ -64,11 +64,13 @@ end
|
||||||
|
|
||||||
function SceneManager:update(dt)
|
function SceneManager:update(dt)
|
||||||
if (self.currentScene ~= nil) then
|
if (self.currentScene ~= nil) then
|
||||||
|
self.currentScene:updateStart(dt)
|
||||||
self.currentScene:setKeys()
|
self.currentScene:setKeys()
|
||||||
self.currentScene.assets:update(dt)
|
self.currentScene.assets:update(dt)
|
||||||
self.currentScene.menusystem:update(dt)
|
self.currentScene.menusystem:update(dt)
|
||||||
self.currentScene:updateWorld(dt)
|
self.currentScene:updateWorld(dt)
|
||||||
self.currentScene:update(dt)
|
self.currentScene:update(dt)
|
||||||
|
self.currentScene:updateEnd(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,9 +110,11 @@ 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:drawWorld()
|
self.currentScene:drawWorld()
|
||||||
self.currentScene:draw(dt)
|
self.currentScene:draw()
|
||||||
self.currentScene.menusystem:draw()
|
self.currentScene.menusystem:draw()
|
||||||
|
self.currentScene:drawEnd()
|
||||||
end
|
end
|
||||||
self.controller.screen:cease()
|
self.controller.screen:cease()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue