Re: flux: A fast, lightweight tweening library
Posted: Sat May 10, 2014 8:27 pm
Totaly missed that, sorry
Thanks
Thanks
You've got a great library, you just need a better marketing department. Sweet mother of gifkikito wrote:This library is really nagging me to update tween.lua.
But I must resist. Not ... yet.
Well, I do consider the name kikito as a quality brand, speaking about code.Lap wrote:You've got a great library, you just need a better marketing department. Sweet mother of gif
Code: Select all
if tween == 0 then
--- some creation code---
tween = 6 --- for the reset back to 6
end
Code: Select all
tween.to(enemyCircleCount, 0, { count = 6 }):ease("linear")
:after(enemyCircleCount, 0, { count = 0 }):ease("linear"):loop(1)
The :loop() function is something that was suggested before, but unfortunately adding it in would increase the complexity of flux by quite a bit, and would require a reworking of how everything works internally.smoking bunny wrote:[...] though im finding it hard to find, but is there a 'loop' type of functions [...]
Code: Select all
local flux = require "flux"
function love.load()
circle = { x = 400, y = 300, size = 0, color = { 255, 255, 255 } }
-- Do looped tween sequence 4 times
local count = 4
local function sequence()
-- Abort if we hit our repeat limit
count = count - 1 -- Omit this to repeat forever
if count == 0 then return end -- and this
-- Do tween
flux.to(circle, 2, { size = 100 }):ease("elasticout")
:after(circle.color, 1, { 255, 0, 0 })
:after(circle.color, 1, { 0, 255, 0 })
:after(circle.color, 1, { 0, 0, 255 })
:after(circle, 1, { size = 0 }):ease("quadin")
:oncomplete(sequence) -- Intialise the next iteration of the sequence
end
-- Intialise the first iteration of the sequence
sequence()
end
function love.update(dt)
flux.update(dt)
end
function love.draw()
love.graphics.setColor(unpack(circle.color))
love.graphics.circle("fill", circle.x, circle.y, circle.size)
end
Code: Select all
if enemyCountDown == 0 then
return math.floor (enemyCountDown + 0.5)
end
Code: Select all
flux.to(self.fadein, 0.35, { alpha = 1 }):ease('linear'):oncomplete(
function()
loader.start(
function()
flux.to(self.fadein, 0.35, { alpha = 0 }):ease('linear'):oncomplete(
function()
self:gotoState( nextscene )
end
)
end
, print)
end
)
Assuming you meant that you want flux to round the number it sets, you can do this using the nupdate function to set the tween value to the rounded value with each update:smoking bunny wrote:actually, have one last thing to round it all up, which is just that, rounding the numbers. [...]
Code: Select all
local t = { n = 0 }
flux.to(t, 10, { n = 100 })
:onupdate(
function()
t.n = math.floor(t.n + .5) -- Round .n after the tween changes it
end)
I'm a little confused what the issue is -- Are you sure its an issue with flux and not an issue with loader.start() calling the function you passed to it twice?SiENcE wrote:I have a question.
onComplete is called everytime a tween ends. Now, how do I know when all of the tweens has ended?
In my example "self:gotoState( nextscene )" is called twice, which is no good.
It should fadein, oncomplete should call love-loader and when love-loader is finished it calls flux for fadeout. After fadeout flux calls goto next State.
[...]
Code: Select all
local flux = require "flux"
function love.load()
circle = { x = 400, y = 300, size = 0, color = { 255, 255, 255 } }
text = ""
local function output(str) text = text .. str .. "\n" end
flux.to(circle, 3, { size = 100 }):ease("expoout")
:oncomplete(
function()
output("first tween finished")
flux.to(circle, 3, { size = 0 }):ease("expoin")
:oncomplete(
function()
output("second tween finished")
end)
end)
end
function love.update(dt)
flux.update(dt)
end
function love.draw()
love.graphics.setColor(unpack(circle.color))
love.graphics.circle("fill", circle.x, circle.y, circle.size)
love.graphics.print(text, 20, 20)
end