improvement: add new transition types

This commit is contained in:
Kazhnuz 2021-04-02 22:00:33 +02:00
parent e08e689586
commit ab3e4eadd8
5 changed files with 83 additions and 3 deletions

View 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

View 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

View 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

View file

@ -1,3 +1,4 @@
return {
default = require "core.modules.transitions.default"
default = require "core.modules.transitions.default",
circle = require "core.modules.transitions.circle"
}

View file

@ -48,6 +48,7 @@ end
function ScreenManager:startTransition(transitionIn, transitionOut, func, x, y)
self.transition = transitionIn(func, x, y, false)
self.transitionOut = transitionOut(nil, x, y, true)
self.isOpaque = true
end
function ScreenManager:transitionOver(fadeOut)
@ -55,6 +56,7 @@ function ScreenManager:transitionOver(fadeOut)
self.transition = self.transitionOut
else
self.transition = nil
self.isOpaque = false
end
end
@ -132,8 +134,14 @@ function ScreenManager:cease()
end
function ScreenManager:drawTransition()
if (self.isOpaque) then
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