improvement: add new transition types
This commit is contained in:
parent
e08e689586
commit
ab3e4eadd8
5 changed files with 83 additions and 3 deletions
33
sonic-radiance.love/core/modules/transitions/canvas.lua
Normal file
33
sonic-radiance.love/core/modules/transitions/canvas.lua
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
local TransitionParent = require "core.modules.transitions.parent"
|
||||||
|
local CanvasTransition = TransitionParent:extend()
|
||||||
|
|
||||||
|
function CanvasTransition:new(func, ox, oy, fadeOut, easeIn, easeOut, duration, wait)
|
||||||
|
CanvasTransition.super.new(self, func, ox, oy, fadeOut, easeIn, easeOut, duration, wait)
|
||||||
|
self:generateCanvas(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CanvasTransition:update(dt)
|
||||||
|
CanvasTransition.super.update(self, dt)
|
||||||
|
self:generateCanvas(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CanvasTransition:generateCanvas(dt)
|
||||||
|
self.canvas = love.graphics.newCanvas(424, 240)
|
||||||
|
love.graphics.setCanvas(self.canvas)
|
||||||
|
self:drawCanvas(dt)
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
end
|
||||||
|
|
||||||
|
function CanvasTransition:drawCanvas(dt)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function CanvasTransition:draw()
|
||||||
|
if (self.canvas ~= nil) then
|
||||||
|
love.graphics.setBlendMode("multiply", "premultiplied")
|
||||||
|
love.graphics.draw(self.canvas, 0, 0)
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return CanvasTransition
|
16
sonic-radiance.love/core/modules/transitions/circle.lua
Normal file
16
sonic-radiance.love/core/modules/transitions/circle.lua
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
local TransitionParent = require "core.modules.transitions.canvas"
|
||||||
|
local DefaultTransition = TransitionParent:extend()
|
||||||
|
|
||||||
|
function DefaultTransition:new(func, ox, oy, fadeOut)
|
||||||
|
DefaultTransition.super.new(self, func, ox, oy, fadeOut, "inQuad", "outQuad", 0.35, 0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DefaultTransition:drawCanvas()
|
||||||
|
love.graphics.setColor(0,0,0,1)
|
||||||
|
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
local value = 1 - self.value
|
||||||
|
love.graphics.circle("fill",self.ox, self.oy, 424 * 1.5 * value)
|
||||||
|
end
|
||||||
|
|
||||||
|
return DefaultTransition
|
22
sonic-radiance.love/core/modules/transitions/decal.lua
Normal file
22
sonic-radiance.love/core/modules/transitions/decal.lua
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
local TransitionParent = require "core.modules.transitions.canvas"
|
||||||
|
local DecalTransition = TransitionParent:extend()
|
||||||
|
|
||||||
|
function DecalTransition:new(func, ox, oy, fadeOut, decal)
|
||||||
|
self.decal = decal
|
||||||
|
DecalTransition.super.new(self, func, ox, oy, fadeOut, "inQuad", "outQuad", 0.8, 0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DecalTransition:loadResources()
|
||||||
|
self.decalDrawable = love.graphics.newImage("assets/transitions/" .. self.decal .. ".png")
|
||||||
|
end
|
||||||
|
|
||||||
|
function DecalTransition:drawCanvas()
|
||||||
|
love.graphics.setColor(0,0,0,1)
|
||||||
|
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
local w, h = self.decalDrawable:getDimensions()
|
||||||
|
local value = (1 - self.value) * (240 / h) * 4
|
||||||
|
love.graphics.draw(self.decalDrawable,self.ox,self.oy,0,value, value, w / 2, h / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
return DecalTransition
|
|
@ -1,3 +1,4 @@
|
||||||
return {
|
return {
|
||||||
default = require "core.modules.transitions.default"
|
default = require "core.modules.transitions.default",
|
||||||
|
circle = require "core.modules.transitions.circle"
|
||||||
}
|
}
|
|
@ -48,6 +48,7 @@ end
|
||||||
function ScreenManager:startTransition(transitionIn, transitionOut, func, x, y)
|
function ScreenManager:startTransition(transitionIn, transitionOut, func, x, y)
|
||||||
self.transition = transitionIn(func, x, y, false)
|
self.transition = transitionIn(func, x, y, false)
|
||||||
self.transitionOut = transitionOut(nil, x, y, true)
|
self.transitionOut = transitionOut(nil, x, y, true)
|
||||||
|
self.isOpaque = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScreenManager:transitionOver(fadeOut)
|
function ScreenManager:transitionOver(fadeOut)
|
||||||
|
@ -55,6 +56,7 @@ function ScreenManager:transitionOver(fadeOut)
|
||||||
self.transition = self.transitionOut
|
self.transition = self.transitionOut
|
||||||
else
|
else
|
||||||
self.transition = nil
|
self.transition = nil
|
||||||
|
self.isOpaque = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -132,8 +134,14 @@ function ScreenManager:cease()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScreenManager:drawTransition()
|
function ScreenManager:drawTransition()
|
||||||
if (self.transition ~= nil) then
|
if (self.isOpaque) then
|
||||||
self.transition:draw()
|
if (self.transition ~= nil) then
|
||||||
|
self.transition:draw()
|
||||||
|
else
|
||||||
|
love.graphics.setColor(0,0,0,1)
|
||||||
|
love.graphics.rectangle("fill",0,0,424,240)
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue