Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

composer.removeScene doesn't remove all entities
Started by terry27 Mar 25 2019 04:22 PM

1 reply to this topic
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 1 posts
  • Corona SDK

Hi Guys.

Have written a small app with 6 screens - each performing a different function.

As I move from one screen to the next, I use the following to remove the previous screen:


prevScene = composer.getSceneName("previous")
    if prevScene ~= nil then


I've read and re-read the tutorial on creating scenes in composer, but the tutorial doesn't really address removal/deactivation of buttons from a previous scene.   At one point, the tutorial states:

composer.removeScene( "game" )

Essentially, this command removes and destroys the game.lua scene as if it never existed.


My mileage would suggest it DOESN"T 'destroy the scene as if it never existed', because the problem I have, is that buttons from any previously loaded screen are still active on the current screen, even though they are no longer visible.    This is causing untold issues as you can imagine.

I'd like to think I'm just missing a single line of code somewhere that removes or deactivates the buttons, but can't find any such command.

I'm developing my code on Win10 for Android, and run the beta on a Samsung Galaxy 8.  My simulator is 2017.3184,    The fault was first found in the compiled beta on my phone, but since trialled and found to exist in the simulator also.


Surely there is an easy fix for this. What do I need to do to actually remove, or deactivate the buttons when I remove a scene?


Thanks for any assistance...

[TOPIC: post.html]

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,801 posts
  • Enterprise

Hi Terry and welcome to the Corona Community Forums.


First, 2017.3184 is very, very old. Our current daily build is 2019.3470, so you're almost 300 builds behind. You cannot submit to either Google Play or Apple with 3184. While this has nothing to do with the error you're getting, you really should upgrade to a later version.


If you're inserting your buttons into the scene's view group, they will be properly hidden and you should not be able to interact with the buttons. 


Since they appear to be hiding, you're probably inserting them into the group properly. 

Can you tell us more about about how you're creating the buttons? Can you share the code for the listener function's for the buttons?


Corona's composer.* API's work really well and behave as they should. Removing scenes can be an interesting process and there are multiple strategies around doing this.


First and foremost, you shouldn't need to remove scenes. The reason we don't magically do this for you is that it saves resources since the scene's get cached and make your app run more efficiently.  There are two reasons to remove scenes: 1. they take up too much memory,  2. You need to reset a complex scene back to its original setup and you want to take the quick, shortcut way to do it.


When I work with programmer's and those learning programming, I talk about programmer efficiency. That's a two headed coin. First programmers should write the most efficient code possible so the application runs as efficiently as possible. This is why we cache scenes. The other side of the programmer efficiency is helping you write less code.


Resetting a scene can cause you to have to re-think how you code the scene creation (i.e. create the object in scene:create() but wait to position it to scene:show(). If objects have rotated, scaled, have physics properties active etc. can result in you writing multiple lines of code, where removing the scene before you go to it accomplishes this in a few lines of code, so it's more programmer efficient at the tradeoff of being less programming efficient.


To keep things simple, before I go to a scene, I know what scene I'm going to, so calling:





So unless the goal of removing the scene is to free up resources, and you've coded your scene correctly (inserting in to groups right, making sure touch controls don't propagate to objects under them), this should work.