Create a delay (slow things down)

Hi I wonder if someone could help. I have written a bit of code that basically displays
A word and then expands it from a pin point up to a full size word. The code uses the number function from the example project
Which I have updated to include all the letters of the alphabet.

Anyway my code works fine however it runs way too fast I.e. all done in one frame and the blink of an eye.
So my question really is how do I delay things or slow them down so that the word takes say a second or 2 seconds to expand to full size.


function printword(myword)

for z=1,30 do

        stroke(10, 11, 10, 255) 


        number((WIDTH/2)-((#myword/2)*30), HEIGHT -10, myword, z)    

        stroke(5, 238, 252, 255)


        number((WIDTH/2)-((#myword/2)*30), HEIGHT -10, myword, z)   



Plenty of ways - the easiest, I expect, is to change your “for” line to:

for z=1,30,0.1 do

The last amount is the step - how much it adds on each pass thru the loop. The default is 1. Using 0.1 should make it take 10 times as long. Tweak to taste.

or control it via the call…

function setup()
    z = 1
function main()
    printword("ARE", z)
    if z > 30 then z = z + .1 end

You’d have to comment out/remove the for/end in printword.

Yet another approach would be to pace/trigger your timing against the ElapsedTime() function. The advantage here would be the device proofing of your own code against faster and faster processors… (iPad 3 I am looking at you).

Thanks for your help. I tried bortels advice but that gave the same result I guess that’s because the for loop is still counting to 30 in one frame regardless of skip rate. Ipda suggestion works however this only works for 1 word . I’m trying to use the function over and over again with different words. If I reset z to 1 and try a different word the code then try’s to do the first word as well. Basically I’m trying to get a game to say “ARE” “YOU” “READ” one word at a time in the same position befor the level in the game starts. I think I can probably do this using ipda’s suggestion but not using a function and just using different variables in each for loop for each word however that doesn’t seem like the proper way to go about it. I have had a look at the elapsedtime function but I,m not quite getting it. Could you possible give an explanation for me and maybe an example. Only been using lua since Christmas so still a bit of a newbie in terms of game development but have lots of application development experience in oracle, vb etc. the once per frame thing keeps throwing me.

Hi Eedoboy,

Sorry, I should have been more specific (but I’m pretty much a newbie like yourself)…

Have look at this discussion on the use of ElapsedTime() and see if it helps you. If not let us know.

Welcome to the front end :slight_smile:

(note: Elaspedtime doesn’t increment within a draw() loop only “in between frames”