3
votes

So basically I have a problem using Composer in the Corona SDK. I have a level, and when the lose condition is met, it runs a showOverlay command which pops up a Game Over overlay. I create all the text objects and buttons for the overlay in the scene:create() function and that works fine.

Here is the problem, I placed a print statement in the scene:show() function, inside my code block for

if phase == "will" then end

The documentation claims scene:show is only called twice, once for the "will" phase and once for the "did" phase. Yet my print statement is being printed to the console SEVERAL times, like 15-20 times. In fact, I have noticed this before in other cases where it seems like these event callback functions are being fired more times than they are supposed to.

Is there something I am missing that you have to do or add to these callback functions to make them run the appropriate amount of times?

1

1 Answers

1
votes

Well I found the issue...

I had a Runtime "enterFrame" event listener that was running a function every frame. My if statement for the lose condition was in this function. (if livesRemaining == 0 is the actual condition)

Inside this function, I remove the "enterFrame" event listener, and then run composer.showOverlay(). However, it seems that even though I cancelled the "enterFrame" event listener, it still fires the function associated with it a few more times before the cancellation actually occurs. This made it seem as though the overlay's scene:show was being called multiple times. In fact it actually was, but the real reason is because the composer.showOverlay() function was being called several times before the Runtime "enterFrame" event listener was actually cancelled.

I would think that removing the enterFrame event listener would do so immediately, but I guess it waits a few more cycles before it actually does. Perhaps they will fix this sometime in the future so that we wont have to use a workaround to get stuff working.