开发者

Does Flex/Actionsctipt/Flash implements a mechanism for reusing Sprites?

开发者 https://www.devze.com 2022-12-22 20:28 出处:网络
I\'m creating a game and I create sprites(enemies). I keep creating an开发者_开发百科d destroying sprites. Flash/Flex has a garbage collector which handles the destruction of unused resources. Should

I'm creating a game and I create sprites(enemies). I keep creating an开发者_开发百科d destroying sprites. Flash/Flex has a garbage collector which handles the destruction of unused resources. Should I create an object pool to reuse them, or should I leave flash/flex to handle the creation/destruction of objects?

Which option is better from the performance point of view?


Leave it to the Flash player to handle and only worry about optimisation if there turns out to be a performance problem. Its all hypothetical until then anyway.


Object Pooling is an excellent idea if you need to create/destroy lots of items. Flex 4 is doing this with their DataGroup for managing creating destroying itemRenderers while you scroll through huge lists, and it dramatically improves rendering performance.

And all of the particle frameworks HAVE to use this to be competitive.

Check out these Object Pooling Demos and Presentations for Actionscript:

  • Object Pooling in AS3 by Lost in Actionscript.
  • Polygonal Labs' ObjectPool class and some examples.
  • Object Pools prevent "stuttering" example.
  • Grant Skinner describes some bits about Object Pooling in his Presentation, among other neat things.

I'd recommend using an object pool if you're creating/destroying lots of objects. Performance optimizations are very important early on if you're building a complex project and you won't have time to go back to it for a while. Object Pooling goes a long way and is very easy to implement.

Hope that helps, Lance

0

精彩评论

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