Hiding / showing objects

To hide an object use the following:

To show an object use the following:

To query the hidden state of any object use the following:

var hidden = obj.hidden;
It is also possible to permanently remove an object from a scene. To do this use the following:

Destroying and re-adding an object can be resource-consuming compared to hiding and reshowing an object. Thus it is reasonable to use an object-pool with a couple of hidden objects if certain types of objects can appear and disappear in the scene from time-to-time. A good example for this would be rockets launched by a character: a rocket is typically a SheetObject because it can move around and a character can fire multiple rockets that later explode (disappear). In this case it is better to create a number of rockets, hide them, and when the character fires take one rocket, show it and reposition it to the start location, than to destroy it and add it to the scene every time.

Last edited Dec 11, 2012 at 1:56 AM by dobsonl, version 1


No comments yet.