Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Delaying tweens

edited February 2013 in Questions Posts: 58

I have some tweens that I implement into my project at a certain point, but I don't want the tweens to start until I hit another button. Is there any way to delay the tweens from happening right as I call them? Thx in advance

Comments

  • just cut one tween into two: one start on call and second start when y hit button.

  • Posts: 58

    @Cabenet, that's what I ending up doing, and it worked, I was just wondering if there was a delay function or at least a way to not start tweens on call

  • SimeonSimeon Admin Mod
    Posts: 4,927

    At the moment I don't think there is a way to do this. I'm looking at adding a tween.play() function to 1.5.1 so you can create them, call tween.stop(id) then tween.play(id) to resume them.

  • Runtime - simeon_n - Added a tween.play function to tween.lua

    Done :)

  • SimeonSimeon Admin Mod
    Posts: 4,927

    .@Cabernet it needs a bit of testing to make sure it doesn't blow up with paths and sequences.

  • Jmv38Jmv38 Mod
    edited February 2013 Posts: 3,295

    I had some problems with tween with a time of 2s, starting as the result of a tap, and then tap tap taping several times fast: the started tween isnt finished but a new one tries to start, then the result is confusing. I guess it's my business to manage the 'too fast tap' problem, and not allow a new tween to start before the previous is finished, or kill the curernt one. But it makes the use of tween more complex, while tween are supposed to be here to make things simple. Have you thought of something like 'automatic tween reset' when it concerns the same variable? Actually i used tween some months ago, so maybe you've already solved that and my question is obsolete?

  • dave1707dave1707 Mod
    edited February 2013 Posts: 7,553

    Here's an example of starting, pausing, continuing, or restarting a tween. This won't work for all types of Tweens the way it is, but it's a start.


    displayMode(FULLSCREEN) supportedOrientations(PORTRAIT) function setup()     show=false     stop=true     c1x=100    -- subject start x value     c1y=100    -- subject start y value     c1t=4    -- tween time     setup1() end function setup1()     circ={x=c1x,y=c1y}    -- create subject with x,y values end function setup2()     t1=tween(c1t,circ,{x=700,y=900})    -- create tween with subject values end function draw()     background(40, 40, 50)     fill(255)     text("tap screen to start or stop the tween",WIDTH/2,900)     text("triple tap to restart",WIDTH/2,850)     ellipse(100,100,10)    -- visual starting point     ellipse(700,900,10)    -- visual ending point     ellipse(circ.x,circ.y,40)    -- draw tween subject end function touched(t)     if t.state==BEGAN then         if t.tapCount==3 then    -- restart             setup()         elseif stop then             stop=false             st1=ElapsedTime             setup1()    -- recreate subject             setup2()    -- recreate tween         else             tween.stop(t1)    -- stop tween             stop=true             st2=ElapsedTime             c1x=circ.x    -- save subject x value             c1y=circ.y    -- save subject y value             c1t=c1t-(st2-st1)    -- time left of original time             if c1t<0 then                 c1t=.001    -- time can't be 0 or less             end         end     end     end 
  • Posts: 2,161

    I would like a delay as well. I put a tween in setup, but it seemed to start a little bit in to the tween by the time draw was called. So an initial delay would be great.

  • any ideas how to make circle tween?

  • Jmv38Jmv38 Mod
    Posts: 3,295

    There is a circle tween: i've read in another thread (can't remember which one: mpilgrem or dave1707) that it is an undocumented option.

  • Posts: 489

    Hello @Cabernet. My experiment here shows how to use a custom easing function and, also, the built-in circ series of easing functions.

  • Posts: 58

    .@dave I changed your simple tween program to allow to go back the other way. I also came across something interesting (a bug?) I have to make a very short tween that simply moves the object to its current values. It sounds silly, but without it, the object goes back to its position before the tween started, and then continues with the tween

    displayMode(FULLSCREEN)
    supportedOrientations(PORTRAIT)
    
    function setup()
        show=false
        stop=true    
    
        c1x=100    -- subject x value
        c1y=100    -- subject y value
    
        c1t=4    -- tween time
    
        c1tt = 4 -- tween reset time
    
        c1bx=100    -- subject beginning x value
        c1by=100    -- subject beginning y value
    
        c1ex = 700 -- subject ending x value
        c1ey = 900 -- subject ending y value
    
        c1tx = 700 -- subject target x value
        c1ty = 900 -- subject target y value
        setup1()
    end
    
    function setup1()
        circ={x=c1x,y=c1y}    -- create subject with x,y values
    end
    
    function setup2()
        tween(0.00000001, circ, {x = circ.x, y = circ.y})
        t1=tween(c1t,circ,{x=c1tx,y=c1ty}, {easing = tween.easing.linear}, reverseTween)    -- create tween with subject values
    end
    
    function reverseTween()
        c1t = c1tt
        if c1tx == c1bx then
            c1tx = c1ex
        else
            c1tx = c1bx
        end
        if c1ty == c1by then
            c1ty = c1ey
        else
            c1ty = c1by
        end
        setup2()
    end
    
    function draw()
        background(40, 40, 50)
        fill(255)
        text("tap screen to start or stop the tween",WIDTH/2,900)
        text("triple tap to restart",WIDTH/2,850)
        ellipse(100,100,10)    -- visual starting point
        ellipse(700,900,10)    -- visual ending point
        ellipse(circ.x,circ.y,40)    -- draw tween subject
    end
    
    function touched(t)
        if t.state==BEGAN then
            if t.tapCount==3 then    -- restart
                setup()
            elseif stop then
                stop=false
                st1=ElapsedTime
                setup1()    -- recreate subject
                setup2()    -- recreate tween
            else
                tween.stop(t1)    -- stop tween
                stop=true
                st2=ElapsedTime
                c1x=circ.x    -- save subject x value
                c1y=circ.y    -- save subject y value
                c1t=c1t-(st2-st1)    -- time left of original time
                if c1t<0 then
                    c1t=.001    -- time can't be 0 or less
                end
            end
        end    
    end 
    
Sign In or Register to comment.