flux: A fast, lightweight tweening library

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: flux: A fast, lightweight tweening library

Post by Ranguna259 »

Totaly missed that, sorry :P
Thanks
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
smoking bunny
Citizen
Posts: 67
Joined: Wed May 07, 2014 9:04 am
Contact:

Re: flux: A fast, lightweight tweening library

Post by smoking bunny »

thanks for this library. very useful. im just working with timers and fancy using tweens instead of 'dt'

graci
lewis lepton
------
composer | sound designer | tinkerer
smoking bunny | bandcamp | twitter | gitHub | vimeo
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: flux: A fast, lightweight tweening library

Post by Lap »

kikito wrote:This library is really nagging me to update tween.lua.

But I must resist. Not ... yet.
You've got a great library, you just need a better marketing department. Sweet mother of gif :awesome:
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: flux: A fast, lightweight tweening library

Post by Roland_Yonaba »

Lap wrote:You've got a great library, you just need a better marketing department. Sweet mother of gif :awesome:
Well, I do consider the name kikito as a quality brand, speaking about code.
Along with some other names. ;)
User avatar
smoking bunny
Citizen
Posts: 67
Joined: Wed May 07, 2014 9:04 am
Contact:

Re: flux: A fast, lightweight tweening library

Post by smoking bunny »

hola,

its great this library, and has taken away some 9 lines of other timer code i drummed up, so thats always good. plus easier for multiple instances.
though im finding it hard to find, but is there a 'loop' type of function. im guess its just an if statement, but have tried a few of the 'what i think they would be', but no.
say

Code: Select all

if tween == 0 then
--- some creation code---
tween = 6 --- for the reset back to 6
end
if so, would it be possible to have a function like that.
say at the end of a tween, something like this

Code: Select all

tween.to(enemyCircleCount, 0, { count = 6 }):ease("linear")
	:after(enemyCircleCount, 0, { count = 0 }):ease("linear"):loop(1)
just an idea. but would love to know some looping function. say 'loop(1)' would mean on, 'loop(0)' would mean off. as an example

cheers
lewis lepton
------
composer | sound designer | tinkerer
smoking bunny | bandcamp | twitter | gitHub | vimeo
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: flux: A fast, lightweight tweening library

Post by rxi »

smoking bunny wrote:[...] though im finding it hard to find, but is there a 'loop' type of functions [...]
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.

Fortunately there is a means of looping a sequence by using the :oncomplete() function. You simply create a function which initialises your tweens, and on the last tween's :oncomplete() you call the function again. I've attached a small example file showing a sequence repeated 4 times using this technique, code is below:

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
Attachments
tween_loop_example.love
An example of looping a tween sequence
(2.22 KiB) Downloaded 210 times
User avatar
smoking bunny
Citizen
Posts: 67
Joined: Wed May 07, 2014 9:04 am
Contact:

Re: flux: A fast, lightweight tweening library

Post by smoking bunny »

@rxi
brilliant, thanks a bunch.
i did see and look up oncomplete, but was just unsure of 'how' to implement it.
agree that the loop feature would be a bitch to implement. but if you do, im 100% for it. but if not, then fair enough.

thanks again

#edit
also, it does work as well. brilliant. thanks
lewis lepton
------
composer | sound designer | tinkerer
smoking bunny | bandcamp | twitter | gitHub | vimeo
User avatar
smoking bunny
Citizen
Posts: 67
Joined: Wed May 07, 2014 9:04 am
Contact:

Re: flux: A fast, lightweight tweening library

Post by smoking bunny »

actually, have one last thing to round it all up, which is just that, rounding the numbers.
how could i go about this. i have done the one with lua

Code: Select all

if enemyCountDown == 0 then
    		return math.floor (enemyCountDown + 0.5)
  		end
would this be the same with rounding flux numbers? i have tried the same thing, but its not working.
lewis lepton
------
composer | sound designer | tinkerer
smoking bunny | bandcamp | twitter | gitHub | vimeo
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: flux: A fast, lightweight tweening library

Post by SiENcE »

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

	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
		)
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: flux: A fast, lightweight tweening library

Post by rxi »

smoking bunny wrote:actually, have one last thing to round it all up, which is just that, rounding the numbers. [...]
Assuming you meant that you want flux to round the number it sets, you can do this using the :onupdate function to set the tween value to the rounded value with each update:

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)
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.
[...]
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?

I made a small example showing :oncomplete() not being called twice:

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
If I'm misunderstanding would you be able to create a small .love file which does nothing but demonstrates the issue, with an explanation of what you expect to happen?
Attachments
oncomplete.love
(2.12 KiB) Downloaded 176 times
Post Reply

Who is online

Users browsing this forum: No registered users and 84 guests