Frustrating issue game menu buttons

First time back in the forum since Corona became Solar. Greets to all!

I am having a frustrating issue. I have a main menu scene which shows some buttons for how to proceed (e.g. play game, view high scores, how to play, etc.)
Right now these appear with an elastic bounce when the scene is displayed, which adds to the look and feel and makes it more fun. The problem is that when one of these buttons are pressed, I go to a new scene based on what they chose. When they return from that scene to the main menu, the buttons are all there momentarily, then they abruptly disappear, then bounce back in. Ugly.
I complete understand why this is happening, so I then chose to set the alpha for each button to 0 when they are pressed, hoping that would hide them from the scene so that when the user returns they won’t be visible (and get the ugly double flash). I have tried doing this in the button clicked event for each button, I have tried doing this in the main menu’s scene:hide event.
Most of the time it’s fine, but 30-40% of the time there will be a random number of buttons which don’t get hidden, so when the user returns to the main menu, there will be 1, 2 or even 3 buttons which initially show, then are hidden, then bounce back in.
So this seems to be some sort of timing issue (?).
I guess I could just go back and get rid of the fun bounce, but now I really like how it makes the game’s main menu ‘feel’, so I’d like to figure this out.
Any suggestions on where I am going wrong?

Are you adding the buttons to the scene group using sceneGroup:insert(myObject) in scene:create()

Also try https://docs.coronalabs.com/api/library/composer/recycleOnSceneChange.html

Thanks for the response.

Yes. all are inserted using sceneGroup:insert() during the scene:create() event.

I will try using the ‘composer.recycleOnSceneChange = true’ but am wary of having to go through and test every aspect of every scene change just to make this one thing work the way I think it should. :slight_smile:

Just tested using composer.recycleOnSceneChange = true and it seems to have solved this issue. Thanks for the advice!

Using composer.recycleOnSceneChange = true may be something of a cop out as you are removing the old scene entirely to address one issue.

All you’d need to do is to:

  1. When leaving the menu scene, in the “did” phase for scene:hide(), you’d loop through your buttons and position them back to their initial coordinates (from where you are transitioning them to). You wouldn’t transition them at this point, you’d just assign their x and y positions.
  2. When returning / creating the menu scene, in the “did” phase for scene:show(). you’d run the transitions to reveal the buttons (again).

If there are cases where some of the buttons are not moving, it’s likely due to some of the buttons not being properly scoped, i.e. you may be overwriting the variables.

Thanks. What you described above is what I was doing.
What was at issue was that often when transitioning to the next scene a random number of buttons would still be visible on screen as the scene changed. Sometimes all would disappear, but sometimes 1, 2, 3 or even more would remain. This felt like a timing issue of some sort, so I increased the transition time from .333 seconds to 1 second and then it seemed to be fine, but the app didn’t feel as snappy. The fact that sometimes it worked fine, but then sometimes a random number of buttons remain made me feel that it probably wasn’t a scoping issue, but rather something to do with timing.
I also tried to build and then run on the device (instead of the emulator) just in case it was something on my dev machine’s video drivers, or in the emulator itself but it behaved similarly on the device.
And I agree that (at least to me) it feels like a cop-out, but it’s certainly less of a code smell than inserting artificial delays (which fixed the issue as well) but felt very kludgy. :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.