开发者

What is the display list in Flash 10? Array? Linked list?

I'm working on a game that has many elements on stage, so I'm looking to optimize my loops. I know that Vector is faster than looping an array, but I开发者_JAVA技巧'm also in some cases using:

while (i < numChildren)
    getChildAt(i)

...to update sprites.

My question is when I use getChildAt, is that accessing an Array or Vector or linked list or other? Should I instead store references to my objects in a Vector and loop through that instead?


if you have a lots of elements on the stage, most of the time is probably spent rendering them.
also, it matters only little, how the child-list of DisplayObjectContainer is implemented, since the cost for function calls is orders of magnitude higher than access of Vectors or Arrays. I guess in fact the child-list is implemented using a C/C++ collection, instead of having all the overhead coming from ActionScript builtin collections.

So yes, storing all children in a Vector will allow faster lookup, although deletion will become expensive. Even insterting will become either more expensive (if you override all child manipulation methods to update the vector when making changes and listen to remove events) or more difficult.

you should run your game with the root sprite turned invisible, to see how much it consumes.
From my experience, this optimization will not yield any signifficant speedup. You should rather try to learn about existing optimization techniques for flash games.

greetz
back2dos


According to the docs, getChildAt() is a fast hash-table lookup (as compared to getChildByName() which is a (relatively) slower linked-list traversal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜