AddToLayer
Last updated
Was this helpful?
Last updated
Was this helpful?
The AddToLayer object adds an existing object instance to the argument . The first argument object may or may not already be added to the SpriteManager. If the object is an unlayered object then it will be removed from the "world layer" and added to the argument . However, if an object is already part of a different it will continue to hold that membership after this call as well as being a member of the new . In other words, this method can be called multiple times to have an object be drawn on multiple .
The AddToLayer is very simple to use. Assuming you have a valid and a valid object that can be added to the , you can add it as follows:
The SpriteManager's AddToLayer method can be useful but suffers a small performance penalty when called on which have already been added to the . For example, the following code is functional but suffers a small performance penalty.
This code is functionally identical but slightly more efficient.
Why is this expensive? The SpriteManager.AddSprite method tells the that the being added should be managed and drawn by the SpriteManager. This places the Sprite in the same category as unlayered Sprites. Calling SpriteManager.AddToLayer then places the on the argument layer. However, the SpriteManager must then remove the argument sprite from its internal . The following code is more efficient and preferred: