For some of my games, I'm using a modified version of stateswitcher.lua that allows for scene transitions.
You simply use it like
Code: Select all
state.switch("game", "fromLeft", function() print("I'm done !") end)
--state.switch(scene, transition, oncomplete)
Transitions include fromLeft, fromRight, fromTop, fromBottom
Also, you need to use love.updateScene(dt) and love.drawScene() instead of love.update(dt) and love.draw().
Code: Select all
--[[
State switcher class: stateswitcher.lua
Author: Daniel Duris, (CC-BY) 2014
dusoft[at]staznosti.sk
http://www.ambience.sk
License: CC-BY 4.0
This work is licensed under the Creative Commons Attribution 4.0
International License. To view a copy of this license, visit
http://creativecommons.org/licenses/by/4.0/ or send a letter to
Creative Commons, 444 Castro Street, Suite 900, Mountain View,
California, 94041, USA.
modified by some guy
]]--
passvar={}
state={}
s_g = {updateCurrent = nil, updateOld = nil, drawCurrent = nil, drawOld = nil, unload = nil, delta = nil, translate = nil}
function state.switch(state, transition, oncompletetransition)
if love.unload then love.unload() end
passvar={}
local matches={}
for match in string.gmatch(state,"[^;]+") do
matches[#matches+1]=match
end
state=matches[1]
matches[1]=nil
if (matches[2]~=nil) then
for i,match in pairs(matches) do
passvar[#passvar+1]=match
end
end
-- remove info from metatable about state loaded to allow for new require of the state
package.loaded[state]=false
s_g.updateOld = love.updateScene
s_g.drawOld = love.drawScene
s_g.unload = love.unload
require(state)
s_g.updateCurrent = love.updateScene
s_g.drawCurrent = love.drawScene
if transition == nil then
s_g.updateOld = nil
s_g.drawOld = nil
else
s_g.delta = 1
if transition == "fromLeft" then
s_g.translate = {x = -WWIDTH, y = 0}
elseif transition == "fromRight" then
s_g.translate = {x = WWIDTH, y = 0}
elseif transition == "fromTop" then
s_g.translate = {x = 0, y = -WHEIGHT}
elseif transition == "fromBottom" then
s_g.translate = {x = 0, y = WHEIGHT}
end
flux.to(s_g, 0.75, {delta = 0}):ease("quadout"):oncomplete(function()
s_g.updateOld = nil
s_g.drawOld = nil
if s_g.unload then s_g.unload() end
oncompletetransition()
end)
end
love.load()
end
function state.clear()
passvar=nil
end
function love.update(dt)
s_g.updateCurrent(dt)
if s_g.updateOld then s_g.updateOld(dt) end
end
function love.draw()
--Manager:drawF(1)
love.graphics.push()
if s_g.drawOld then
if s_g.delta and s_g.delta > 0 then
love.graphics.translate(s_g.delta*s_g.translate.x-s_g.translate.x, s_g.delta*s_g.translate.y-s_g.translate.y)
end
s_g.drawOld()
end
if s_g.delta and s_g.delta > 0 then
love.graphics.translate(s_g.translate.x, s_g.translate.y)
end
s_g.drawCurrent()
love.graphics.pop()
--Manager:drawF(2)
end
return state