How can I wait or force Corona to display an object before continuing forward with my code?

I’ve tried two sets of code - both don’t work. When I run them, nothing shows up on screen and the object doesn’t display.

Why doesn’t this code work to show a rect and not return until it is displayed?

function itsAlive()
     G_testAlive=1
end

function displayAndWaitForItToAppear(msg)
     local obj=display.newRect(0,0,100,100)

     G_testAlive=0
     timer.performWithDelay(1000,itsAlive)
     while G_testAlive==0 do
          – nothing
     end
end

displayAndWaitForItToAppear()

I’ve also tried a runtime “enterframe” listener and that didn’t work, either.

function itsAlive()
     G_testAlive=1
end

function displayAndWaitForItToAppear(msg)
     local obj=display.newRect(0,0,100,100)

     G_testAlive=0
     obj:addEventListener(“runtime”,itsAlive)
     while G_testAlive==0 do
          – nothing
     end
end

displayAndWaitForItToAppear()

Hi Troy,

I’m curious what your goal is here. Do you want to pre-load a texture because it’s very large, and not proceed until it’s loaded?

I really wait to display a Please Wait… message on top of the Rect, and then send my code off to to an inapppurchase. Problem is, that the please wait doesn’t appear before it goes off. So, I created a couple of different examples.

In other words, I want to define the object, see the object, and then continue. So, how can this be done?

@Brent:

I really wait to display a Please Wait… message on top of the Rect, and then send my code off to to an inapppurchase. Problem is, that the please wait doesn’t appear before it goes off. So, I created a couple of different examples.

In other words, I want to define the object, see the object, and then continue. So, how can this be done?

I found the solution - it was to simply loop using a timer.performWithDelay(1,checkAgain) rather than create a while loop

Hi Troy,

I’m curious what your goal is here. Do you want to pre-load a texture because it’s very large, and not proceed until it’s loaded?

I really wait to display a Please Wait… message on top of the Rect, and then send my code off to to an inapppurchase. Problem is, that the please wait doesn’t appear before it goes off. So, I created a couple of different examples.

In other words, I want to define the object, see the object, and then continue. So, how can this be done?

@Brent:

I really wait to display a Please Wait… message on top of the Rect, and then send my code off to to an inapppurchase. Problem is, that the please wait doesn’t appear before it goes off. So, I created a couple of different examples.

In other words, I want to define the object, see the object, and then continue. So, how can this be done?

I found the solution - it was to simply loop using a timer.performWithDelay(1,checkAgain) rather than create a while loop