gamecore: add scene storage system

This commit is contained in:
Kazhnuz 2019-03-16 15:15:01 +01:00
parent 6fcbc7153c
commit d6c6b64786
3 changed files with 20 additions and 1 deletions

View file

@ -35,6 +35,7 @@ function TestScene:update(dt)
end end
function TestScene:mousepressed(x, y) function TestScene:mousepressed(x, y)
core.scenemanager:storeCurrentScene("pausedScene")
examples.Test2() examples.Test2()
end end

View file

@ -35,7 +35,7 @@ function TestScene:update(dt)
end end
function TestScene:mousepressed(x, y) function TestScene:mousepressed(x, y)
examples.Test() core.scenemanager:setStoredScene("pausedScene")
end end

View file

@ -28,12 +28,30 @@ local SceneManager = Object:extend()
function SceneManager:new(controller) function SceneManager:new(controller)
self.controller = controller self.controller = controller
self.currentScene = nil self.currentScene = nil
self.storage = {}
end end
function SceneManager:setScene(scene) function SceneManager:setScene(scene)
self.currentScene = scene self.currentScene = scene
end end
function SceneManager:storeCurrentScene(name)
self.storage[name] = self.currentScene
end
function SceneManager:setStoredScene(name)
local storedScene = self.storage[name]
if storedScene ~= nil then
self.currentScene = storedScene
self.storage[name] = nil
end
end
function SceneManager:clearStorage()
self.storage = {}
end
function SceneManager:update(dt) function SceneManager:update(dt)
if (self.currentScene ~= nil) then if (self.currentScene ~= nil) then
local keys = self.controller.input.keys local keys = self.controller.input.keys