hello all
hello all

Reputation: 252

Does creating Sprite instances without adding them as children decreases performance speed?

I'm building a custom, simple 3D engine in AS3, as simple as possible. It draws everything with Graphics and render it with Bitmap and BitmapData.

For re-ordering the drawing order by z (depth) positions, I use getRelativeMatrix3D of the Transform instance of a Sprite. Here is my question: if I create a lot of Sprite instances but DO NOT ADD THEM AS CHILDREN OF THE STAGE, does it decreases my performance speed?

If it does, then is there a more efficient and useful way of re-ordering WITHOUT ADDING SPRITES AS CHILDREN?

If it doesn't, just tell me.

Thanks! :)

Upvotes: 1

Views: 161

Answers (1)

TheSHEEEP
TheSHEEEP

Reputation: 3132

As correctly pointed out by @Neil in the comments, objects that are not added to the display list (added to Stage) do not affect rendering performance.

However, creating objects with new does always cost time. So if you'd write a function that does nothing but create 1.000 Objects of some kind each frame, you'd likely see a very visible performance drop.

This is true for every language, though, so as a rule of thumb, you should only create new Objects where neccessary.

And even re-use objects that are not needed any more. Have a look at the object pool pattern to see what I mean. As an example, object pools are often used for bullets in a sidescroller. But such things are really part of performance improvements. So if you're short on time and no users are complaining, I would do such optimizations in a refactoring phase. Or you just do it right away, your choice ;)

Upvotes: 1

Related Questions