views:

124

answers:

3

I'm making a multiplayer flash game that has a lot of graphics/code.

I'm having some performance issues with things such as my weather effects.

Like I'm wondering if it's better to use a bitmap graphic or just use the "vector" (what ever format flash images are drawn in the fla) graphics in a large resource heavy game? While not worrying about pre-load times, just worrying about the game performance at playtime

A: 

I don't think there is a generic answer to "bitmaps or vectors"... it all depends on the specific conditions of your game and many other variables... maybe you could narrow it down to more specific questions that could give some ideas.

For the moment I advice you to check for information on the Flash Player internals, specificaly on how it renders graphics and vectors... then make some tests benchmarking some general situation (large graphics versus large vectors, etc...) so you can get a better idea where and how to optimize your application.

Cay
+5  A: 

Flash rendering native Shape/Sprite/MovieClip is great for a trivial number of simpe animations, but if you have many or complex animations going at once, it hits a wall pretty quickly.

In the instances where you determine that rendering is the bottleneck (profiling is your friend) then you can get much quicker performance by creating a Bitmap as a 'view' in your game and using BitmapData's copyPixels function to blit BitmapData representations of your animation frames into that view every frame.

In my latest game, I'm doing exactly this, for exactly this reason. I'm taking the desired MovieClips, stepping through their frames and caching bitmapData representations of each frame by using BitmapData's draw() method to render the frames at load time (which is a little slow) and then using copyPixels to draw them in the view at run time (which is super fast).

Nothing is for free of course, so you have to be mindful that you are trading CPU cycles for memory space in this case, and if you have a lot of long animations, your apps memory usage will skyrocket pretty quickly.

JStriedl
Interesting. Blitting is something I have looked into but haven't got my hands dirty with it as yet. I had read [http://www.photonstorm.com/archives/160/is-pixel-blitting-in-as3-really-worth-the-effort](http://www.photonstorm.com/archives/160/is-pixel-blitting-in-as3-really-worth-the-effort)and their results seem different to yours. They found speed similar but memory usuage was much less with the blitting?
Allan
redo his tests using multi-frame MovieClips rather than Sprites, and add rotation into the mix (which you account for by pre-rotating your cached buffers in a pixel blitting settup) and the performance difference becomes apparent much more quickly. His scenario with all identical non-rotating/scaling single frame sprite with cacheAsBitmap set is essentially using pixel blitting internally.
JStriedl
cheers for that!
Allan
A: 

A direct answer to your question really depends a lot on the circumstances. However, I recently came across the BirdEye AS3 graphics library, which may be of iterest. Based on the demos it's quite performant. You may want to use it, or at least learn from it.

Update: This is a Flex library so may not be of interest if you're using Flash directly.

alexr