refactor + new transitions
This commit is contained in:
@@ -3,7 +3,7 @@ local Tween = require('opus.ui.tween')
|
||||
local Transition = { }
|
||||
|
||||
function Transition.slideLeft(args)
|
||||
local ticks = args.ticks or 8
|
||||
local ticks = args.ticks or 6
|
||||
local easing = args.easing or 'inCirc'
|
||||
local pos = { x = args.ex }
|
||||
local tween = Tween.new(ticks, pos, { x = args.x }, easing)
|
||||
@@ -19,7 +19,7 @@ function Transition.slideLeft(args)
|
||||
end
|
||||
|
||||
function Transition.slideRight(args)
|
||||
local ticks = args.ticks or 8
|
||||
local ticks = args.ticks or 6
|
||||
local easing = args.easing or 'inCirc'
|
||||
local pos = { x = -args.canvas.width }
|
||||
local tween = Tween.new(ticks, pos, { x = 1 }, easing)
|
||||
@@ -50,4 +50,39 @@ function Transition.expandUp(args)
|
||||
end
|
||||
end
|
||||
|
||||
function Transition.shake(args)
|
||||
local ticks = args.ticks or 8
|
||||
local i = ticks
|
||||
|
||||
return function()
|
||||
i = -i
|
||||
args.canvas:move(args.canvas.x + i, args.canvas.y)
|
||||
if i > 0 then
|
||||
i = i - 2
|
||||
end
|
||||
return i ~= 0
|
||||
end
|
||||
end
|
||||
|
||||
function Transition.shuffle(args)
|
||||
local ticks = args.ticks or 4
|
||||
local easing = args.easing or 'linear'
|
||||
local t = { }
|
||||
|
||||
for _,child in pairs(args.canvas.children) do
|
||||
t[child] = Tween.new(ticks, child, { x = child.x, y = child.y }, easing)
|
||||
child.x = math.random(1, args.canvas.parent.width)
|
||||
child.y = math.random(1, args.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
|
||||
return not finished
|
||||
end
|
||||
end
|
||||
|
||||
return Transition
|
||||
|
||||
Reference in New Issue
Block a user