Page 3 of 5

Re: flux: A fast, lightweight tweening library

Posted: Sat May 10, 2014 8:27 pm
by Ranguna259
Totaly missed that, sorry :P
Thanks

Re: flux: A fast, lightweight tweening library

Posted: Sun May 18, 2014 2:04 pm
by smoking bunny
thanks for this library. very useful. im just working with timers and fancy using tweens instead of 'dt'

graci

Re: flux: A fast, lightweight tweening library

Posted: Sun May 18, 2014 3:23 pm
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:

Re: flux: A fast, lightweight tweening library

Posted: Mon May 19, 2014 7:31 am
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. ;)

Re: flux: A fast, lightweight tweening library

Posted: Wed May 21, 2014 9:16 pm
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

Re: flux: A fast, lightweight tweening library

Posted: Thu May 22, 2014 11:12 am
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

Re: flux: A fast, lightweight tweening library

Posted: Thu May 22, 2014 2:03 pm
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

Re: flux: A fast, lightweight tweening library

Posted: Thu May 22, 2014 2:17 pm
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.

Re: flux: A fast, lightweight tweening library

Posted: Thu May 22, 2014 3:16 pm
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
		)

Re: flux: A fast, lightweight tweening library

Posted: Thu May 22, 2014 5:41 pm
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?