Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Repeated and reversed tweens — Gideros Forum

Repeated and reversed tweens

StoffeStoffe Member
edited November 2011 in General questions
1. what is the best way to make a tween repeat infinitely? Currently I'm doing something like

tween.onComplete = function (self) self:setPosition(0);self:setPaused(false) end

or

repeatCount = math.huge

which works, but seems a bit hackish. Just wondering if there's a "right way".

2. more importantly: what's a good way to have a tween repeat back and forth a couple of times, then call a callback?

Practical example: scale an object from 1-3 and back 3-1, repeat the process three times, then call a callback. In this case I want to start a level zoomed out and pulsate the goal-sprite a couple of times to show where it is, then zoom back in to the player.

Do I need to setup a chain of callbacks or something manually, or is there a back-and-forth that can be used with repeatCount that I've missed? :)
Tagged:

Comments

  • atilimatilim Maintainer
    Hi,

    1. I cannot find any other way except yours. Most probably I go with repeatCount = math.huge. It's totally valid. (math.huge-1 == math.huge)

    Also, I've tried to make infinite loops with tween.nextTween = tween but I couldn't :)

    2. You can use reflect = true
    local tween = GTween.new(sprite, 1, {x = 240}, {repeatCount = 4, reflect = true})
    tween.onComplete = function() print("complete") end
  • Thanks!

    Come to think of it, I also think math.huge is a valid way to go about it, even better than -1 and similar that things like this often use in other libs.

    I also couldn't chain the tween itself, which I guess it just as well. I think it doesn't rewind it but assumes it's at 0 when it starts. I think the advice should be math.huge instead of fixing that. :)

    reflect also works just fine, though it surprised me a little that I had to double repeatCount - but that does allow for doing something 2.5 times, so probably a good thing. :)
  • atilimatilim Maintainer
    edited November 2011
    :) Maybe we add a flag like rewind=true that rewinds the tween when it finishes. But also I think it has little use :)
  • :) Maybe we add a flag like rewind=true that rewinds the tween when it finishes. But also I think it has little use :)
    Yeah, actually I think documentation solves all of this. :)
  • atilimatilim Maintainer
    Yeah, actually I think documentation solves all of this. :)
    Exactly. We're on it. :)

  • To repeat a tween infinitely, set repeatCount less or equal 0.
Sign In or Register to comment.