2019-06-28 17:50:02 +00:00
|
|
|
local Tween = require('opus.ui.tween')
|
2017-10-07 04:27:41 +00:00
|
|
|
|
|
|
|
local Transition = { }
|
|
|
|
|
2020-04-22 04:40:59 +00:00
|
|
|
function Transition.slideLeft(canvas, args)
|
|
|
|
local ticks = args.ticks or 6
|
|
|
|
local easing = args.easing or 'inCirc'
|
|
|
|
local pos = { x = canvas.ex }
|
|
|
|
local tween = Tween.new(ticks, pos, { x = canvas.x }, easing)
|
2019-01-30 20:11:41 +00:00
|
|
|
|
2020-04-22 04:40:59 +00:00
|
|
|
canvas:move(pos.x, canvas.y)
|
2017-10-07 04:27:41 +00:00
|
|
|
|
2019-02-06 04:03:57 +00:00
|
|
|
return function()
|
2018-01-24 22:39:38 +00:00
|
|
|
local finished = tween:update(1)
|
2020-04-22 04:40:59 +00:00
|
|
|
canvas:move(math.floor(pos.x), canvas.y)
|
|
|
|
canvas:dirty(true)
|
2018-01-24 22:39:38 +00:00
|
|
|
return not finished
|
|
|
|
end
|
2017-10-07 04:27:41 +00:00
|
|
|
end
|
|
|
|
|
2020-04-22 04:40:59 +00:00
|
|
|
function Transition.slideRight(canvas, args)
|
|
|
|
local ticks = args.ticks or 6
|
|
|
|
local easing = args.easing or 'inCirc'
|
|
|
|
local pos = { x = -canvas.width }
|
2019-01-30 20:11:41 +00:00
|
|
|
local tween = Tween.new(ticks, pos, { x = 1 }, easing)
|
|
|
|
|
2020-04-22 04:40:59 +00:00
|
|
|
canvas:move(pos.x, canvas.y)
|
2017-10-07 04:27:41 +00:00
|
|
|
|
2019-02-06 04:03:57 +00:00
|
|
|
return function()
|
2018-01-24 22:39:38 +00:00
|
|
|
local finished = tween:update(1)
|
2020-04-22 04:40:59 +00:00
|
|
|
canvas:move(math.floor(pos.x), canvas.y)
|
|
|
|
canvas:dirty(true)
|
2018-01-24 22:39:38 +00:00
|
|
|
return not finished
|
|
|
|
end
|
2017-10-07 04:27:41 +00:00
|
|
|
end
|
|
|
|
|
2020-04-22 04:40:59 +00:00
|
|
|
function Transition.expandUp(canvas, args)
|
2018-01-24 22:39:38 +00:00
|
|
|
local ticks = args.ticks or 3
|
|
|
|
local easing = args.easing or 'linear'
|
2020-04-22 04:40:59 +00:00
|
|
|
local pos = { y = canvas.ey + 1 }
|
|
|
|
local tween = Tween.new(ticks, pos, { y = canvas.y }, easing)
|
2019-12-05 20:44:35 +00:00
|
|
|
|
2020-04-22 04:40:59 +00:00
|
|
|
canvas:move(canvas.x, pos.y)
|
2017-10-07 04:27:41 +00:00
|
|
|
|
2019-02-06 04:03:57 +00:00
|
|
|
return function()
|
2018-01-24 22:39:38 +00:00
|
|
|
local finished = tween:update(1)
|
2020-04-22 04:40:59 +00:00
|
|
|
canvas:move(canvas.x, math.floor(pos.y))
|
|
|
|
canvas.parent:dirty(true)
|
|
|
|
return not finished
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Transition.shake(canvas, args)
|
|
|
|
local ticks = args.ticks or 8
|
|
|
|
local i = ticks
|
|
|
|
|
|
|
|
return function()
|
|
|
|
i = -i
|
|
|
|
canvas:move(canvas.x + i, canvas.y)
|
|
|
|
if i > 0 then
|
|
|
|
i = i - 2
|
|
|
|
end
|
|
|
|
return i ~= 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Transition.shuffle(canvas, args)
|
|
|
|
local ticks = args.ticks or 4
|
|
|
|
local easing = args.easing or 'linear'
|
|
|
|
local t = { }
|
|
|
|
|
|
|
|
for _,child in pairs(canvas.children) do
|
|
|
|
t[child] = Tween.new(ticks, child, { x = child.x, y = child.y }, easing)
|
|
|
|
child.x = math.random(1, canvas.parent.width)
|
|
|
|
child.y = math.random(1, canvas.parent.height)
|
|
|
|
end
|
|
|
|
|
|
|
|
return function()
|
|
|
|
local finished
|
|
|
|
for child, tween in pairs(t) do
|
|
|
|
finished = tween:update(1)
|
|
|
|
child:move(math.floor(child.x), math.floor(child.y))
|
|
|
|
end
|
2018-01-24 22:39:38 +00:00
|
|
|
return not finished
|
|
|
|
end
|
2017-10-07 04:27:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return Transition
|