开发者

Are actionscript bitmaps faster than vectors?

开发者 https://www.devze.com 2023-02-23 12:21 出处:网络
I\'m working on a project which draws circles continuously at framerate and animates them around the stage and I\'m running into performance issues.

I'm working on a project which draws circles continuously at framerate and animates them around the stage and I'm running into performance issues.

I'm already converting 开发者_JS百科all objects to bitmapData as soon as they become static. My question is, will converting the circles to bitmapData as soon as they are drawn increase performance? In other words, is animating say, 200 bitmaps (with transparency) faster than 200 vector circles?

Are there any drawbacks to this technique? (I'm thinking opacity problems maybe?)

If they were more complex shapes than circles would the answer be different?

Any other tips on improving performance?

Thanks a lot!


There are several approaches you might consider here:

  1. Bet on the vector renderer by drawing your lines and circles each frame. They'll get re-rendered every time, but then that's what Flash is heavily optimized for, so it's not impossible that this could be faster than the alternatives. (Note that drawing the objects at different sizes each frame might be faster than drawing them each into a Sprite and changing its size.)

  2. Bet against the vector renderer by moving bitmaps around. A simple way to do this (assuming you're drawing the shapes with AS3) would be to draw the shapes into Bitmap objects and then move those around. You may not be happy with the jagginess of the result. Enabling bitmap smoothing will help (but cost some performance).
    Note: cacheAsBitmap will probably not do what you want here, because cached bitmaps get redrawn when the object changes size (not sure about transparency).

  3. Bet on hardware acceleration by using cacheAsBitmapMatrix. This is only available in AIR, so it may not work for you. CABM is similar to cacheAsBitmap, but it doesn't redraw the contents as they rescale. Further, in many cases the bitmap gets handed to hardware, and thus can be rescaled on the GPU. I believe there are platforms where that doesn't work though. This is generally very fast, especially on mobile devices.

  4. Bet on AS3 bitmap handling by blitting stuff into a stage-sized BitmapData. But note even if you do this, you'll still need to decide whether to draw shapes into your big bitmap each frame (like option 1) or draw them into individual bitmaps and blit those (transformed) into the big bitmap each frame (like option 2).

I don't think there's any way to know which option is best without experimenting. I'm almost certain that option 3 will be the best if you're using AIR and if HW acceleration works on your platform, but those may not be true. My gut instinct is that option 4 will not be terribly helpful. Blitting can be very fast when you are drawing lots of of static bitmaps onto the stage untransformed, but in this case you need to be either generating or transforming the content each frame, so my guess is that the benefit of blitting will not occur where your bottleneck is. My best guess is that option 2 will be faster than 1, but you may not be happy with the visuals.


You may want to look into Blitting if you're looking for performance. It's a technique that used to be heavily used in 2D games; in Actionscript, it's implemented via the BitmapData.copyPixels() method.

It's substantially faster the displaylist in many cases; google the term "Blitting in AS3" and you'll find a lot of worthwhile data. 8bitrocket.com has some good tutorials for it as well.


There are a number of reasons you might be experiencing performance issues. It sounds like you're using the Event.ENTER_FRAME event, which produces animation speeds subject to the frame rate. Look into timer based animation using the Timer class along with TimerEvent.TIMER. Using a single Timer object to orchestrate your animation might help you achieve the performance you're looking for.

You can also try calling updateAfterEvent() on the event object in your event handler. I'm not sure if an Enter_Frame event can call updateAfterEvent(), but a TIMER event can.

If the vector circles themselves do not change shape, color, line width, etc. when they animate around the stage, then the process should be quite efficient. The trick is to ensure that they are not rendered each time they change position on the stage, but are only redrawn when one or more of their graphic's properties has changed.

If I had to choose one thing, I'd say you're vectors are redrawing themselves on each screen update.

0

精彩评论

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