Game Development Reference
In-Depth Information
The graph plot of the easeOutBounce function
You just learned how to stop a transition. However, the object still remains on the screen. If this were
a screen that displayed the score between levels, for example, we would want it to disappear. In the
simplest way, we could just turn off the visibility of the object by setting the
isVisible
property to
false
. However, with this method, the object would still remain in memory (though not visible on the
screen) and would be created again; if you were to play a game with a substantial number of levels,
there would be quite a few objects on the screen taking up valuable memory.
A better way to remove these objects is to remove them from the stage. When we create an object,
it is added to the stage or the parent object automatically. To remove an object, we simply pass the
object handle to the
remove()
function in the
display
namespace. For instance, to remove the text in
the preceding example , we just pass it the following:
display.remove(theText)
Another way to remove the objects—which seems simpler and more direct—is to call the
removeSelf
function of the display object:
theText:removeSelf()
Note
If the object is already removed or is
nil
, then the
removeSelf
function will fail and give an error.
However, the
display.remove
function exits gracefully without any errors if the object being removed has
previously been removed.