Sam Hogan
Sam Hogan

Reputation: 179

Corona sdk delay an enterFrame function as scene starts

I have multiple scenes in my game, and in one of the scenes, a physics ball is followed by moving all other objects in a group called "game".

local function loop(event)

    local targetx = 600 -ball.x

    if targetx>2550 then
        targetx = 2550
    elseif targetx < display.contentWidth - 1451 then 
        targetx = display.contentWidth-1451
    end
    game.x = game.x + ((targetx - game.x) *0.2)
end

Runtime:addEventListener("enterFrame", loop)

This may not matter because all I need is this function not to take place until 1 second after the scene is entered. How would I do this?

Upvotes: 2

Views: 623

Answers (2)

Krishna Raj Salim
Krishna Raj Salim

Reputation: 7390

Do like this:

local function loop(event)
   ...
   ...
end

local function triggerListener()
  Runtime:addEventListener("enterFrame", loop)
end
timer.performWithDaelay(1000,triggerListener,1) -- Params: time in mS,function,loop

Keep Coding................. :)

Upvotes: 2

Federico Capello
Federico Capello

Reputation: 1118

Have a look at this. It's Corona timer.performWithDelay()

Upvotes: 2

Related Questions