Howdy, Stranger!

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

Delay Commands

How do I set up a command delay so that after a few seconds the line executes and does something new in an animation?

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,155

    You create a timer that get set when you do something. After the timer reaches 0, it executes your animation code. Here’s a simple example.

    function setup()
        x=0
        dec=0
        timer=120
    end
    
    function draw()
        background(0)
        fill(255)
        text("Tap screen to set timer.",WIDTH/2,HEIGHT-100)
        sprite("Planet Cute:Character Horn Girl",x,HEIGHT/2)
        text("Timer  "..timer,WIDTH/2,300)
        if timer>0 then
            timer=timer-dec
        else
            x=x+1
        end
    end
    
    function touched(t)
        if t.state==BEGAN then
            dec=1
        end
    end
    
  • Thanks, I found something else that worked perfectly as well.

    I didn’t know there was tween.sequence, but once I found it I was completely able to make it all work out.

  • Posts: 491

    There are two possibilities:
    1. setup a timer as @dave1707 suggested and act with a callback when timer expires (note that tweens are also timers)
    2. use coroutines to chain multiple actions. I wrote something about it in this thread

Sign In or Register to comment.