Muzahir Hussain
Muzahir Hussain

Reputation: 1033

How to wait in Corona

How can I wait after performing a task in corona.

timer.performwithdelay()

waits before performing a task but I want to wait after performing a task. Is there any way to do that. Actually I want to display an image for 5 seconds.

Upvotes: 0

Views: 1063

Answers (3)

GoojajiGreg
GoojajiGreg

Reputation: 1183

If the task you want to perform is just a transition (like fading out) on a DisplayObject after instantiating the object, keep in mind the delay parameter available on all the functions of the transition library in Corona.

For example, to hide your image 5 seconds after creating it:

local image = display.newImage(...
transition.fadeOut( image, { delay = 5000, time = 250 }

If you want to remove the image DisplayObject from the scene after it fades out, you could add a completion handler:

local image = display.newImage(...

local function onFadeOutComplete( obj )
    obj:removeSelf()
    obj = nil
end

transition.fadeOut( image, {delay = 5000, time = 250, onComplete = onFadeOutComplete } )

Upvotes: 0

ldurniat
ldurniat

Reputation: 1702

Try

local image

function afterTimer()
    -- hide image
    image.alpha = 0 
    -- or use
    -- image.isVisible = false
    -- or remove it 
    -- display.remove(image); image = nil
end

image = display.newImage("nameOfImage.png")

timer.performWithDelay(5000, afterTimer, 1) 

Upvotes: 1

Piglet
Piglet

Reputation: 28950

https://docs.coronalabs.com/api/library/timer/index.html

https://forums.coronalabs.com/topic/50088-how-to-wait-a-certain-amount-of-time/

function afterTimer()
    print("Timer is done!")
    print("Now do something else")
end

timer.performWithDelay(3000, afterTimer, 1)

Upvotes: 0

Related Questions