Timer/wait?

I've been looking around but can't find a way to add a sleep or wait function.

Say I want to wait 1000ms before a function is called- how would I do that?

Thanks a ton to anyone who can help!

Would you mind posting some code for a reference?

Basically... you need to create a function, then you can use this code

1
timer.performWithDelay( 1000, functionNameHere, 1 )

Thanks for that- I'll be sure to save it for future reference. I'm actually not going to have to use that though because I've changed the way my program functions.

This is a simple multi-color strobe, but I'm having performance issues. It starts off fast, but overtime slows to ~1 FPS. I guessed that it kept drawing rectangles over each other to the point where there were thousands, and I thought I had fixed that through doing object:removeSelf() but it doesn't seem to work. If anyone could tell me what I'm doing wrong that would be very helpful- thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
_W = display.contentWidth
_H = display.contentHeight
 
strobeTime = 5
 
local function pinkLight()
        local pink = display.newRect( 0, 0, _W, _H ) 
        pink:setFillColor(255, 105, 180)
        transition.to( pink, { time=strobeTime, onComplete = redLight} )
        yellowLight:removeSelf()
end
        
local function yellowLight()
        local yellow = display.newRect( 0, 0, _W, _H ) 
        yellow:setFillColor(255, 255, 0)
        transition.to( yellow, { time=strobeTime, onComplete = pinkLight} )
        whiteLight:removeSelf()
end
 
local function whiteLight()
        local white = display.newRect( 0, 0, _W, _H ) 
        white:setFillColor(255, 255, 255)
        transition.to( white, { time=strobeTime, onComplete = yellowLight} )
        blueLight:removeSelf()
end
        
local function blueLight()
        local blue = display.newRect( 0, 0, _W, _H ) 
        blue:setFillColor(0, 0, 255)
        transition.to( blue, { time=strobeTime, onComplete = whiteLight} )
        greenLight:removeSelf()
end     
 
local function greenLight()
        local green = display.newRect( 0, 0, _W, _H ) 
        green:setFillColor(0, 255, 0)
        transition.to( green, { time=strobeTime, onComplete = blueLight} )
        redLight:removeSelf()
end
        
        function redLight()
        local red = display.newRect( 0, 0, _W, _H ) 
        red:setFillColor(255, 0, 0)
        transition.to( red, { time=strobeTime, onComplete = greenLight} )
        pinkLight:removeSelf()
        end
        
pinkLight()

Shameless self bump.

remove objects, not a functions, pink:removeSelf() , but this is a waste too, just create them all at the start and play with the alpha= in transition to. 1 is visible 0 is not.

Ah, that's a great idea, I'll try that now. Thanks!

views:1013 update:2011/9/27 8:54:05
corona forums © 2003-2011