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
function TestScene:mousepressed(x, y)
core.scenemanager:storeCurrentScene("pausedScene")
examples.Test2()
end

View file

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

View file

@ -28,12 +28,30 @@ local SceneManager = Object:extend()
function SceneManager:new(controller)
self.controller = controller
self.currentScene = nil
self.storage = {}
end
function SceneManager:setScene(scene)
self.currentScene = scene
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)
if (self.currentScene ~= nil) then
local keys = self.controller.input.keys