From 055ae92eb9d91d0ecbc1a66cd6c76cd93c7092c6 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 13 Jun 2019 18:33:29 +0200 Subject: [PATCH] feat(scene): add *Start() and *End() functions. Make the scene children able to add functions before or after everything. --- examples/basic/test_scene2/init.lua | 5 ++++- gamecore/modules/scenes.lua | 16 ++++++++++++++++ gamecore/scenemanager.lua | 6 +++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/examples/basic/test_scene2/init.lua b/examples/basic/test_scene2/init.lua index 447f4ae..ad2cd27 100644 --- a/examples/basic/test_scene2/init.lua +++ b/examples/basic/test_scene2/init.lua @@ -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) diff --git a/gamecore/modules/scenes.lua b/gamecore/modules/scenes.lua index 3ae1f46..9da7c83 100644 --- a/gamecore/modules/scenes.lua +++ b/gamecore/modules/scenes.lua @@ -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() diff --git a/gamecore/scenemanager.lua b/gamecore/scenemanager.lua index 5a9f88f..b1a8af6 100644 --- a/gamecore/scenemanager.lua +++ b/gamecore/scenemanager.lua @@ -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