Good Resource for Flash/AS3 Perforamace Tips/Tricks for Games
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
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.
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.
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.
精彩评论