Robin Rodricks
Robin Rodricks

Reputation: 114126

Drawing API speed vs embedded graphics

In Flash, you can embed MovieClips drawn in the Flash IDE into a SWF, and then create instances of this using its class path, like car = new Car(). Are such embedded assets slower than using the Drawing API (ie, moveTo, lineTo) in terms of code execution time or rendering time?

I searched everywhere on the internet, but found nothing to elaborate on this issue. Except for this one SO post that says "Use drawing API for faster code execution".

Of course rendering into a bitmap and reusing this for later would be the fastest, but at some point you need to render vector graphics into a bitmap and use either of the above methods to do so.

Do you know which is faster and why?

Upvotes: 1

Views: 236

Answers (1)

Jason Sturges
Jason Sturges

Reputation: 15955

Regardless of the source, any vector asset must be drawn and redrawn on stage invalidation signaling rendering of the display list.

I do not believe authoring tools via Flash Pro's artboard translate to significant optimization. More complicated than it may seem, factors such as timeline layer element groups, shadows, gradients, and primitives such as rounded rectangles may be handled differently. As well, lines created with the pencil tool require less memory than brush strokes.

As with Flash Catalyst, I believe Flash Pro renders each vector individually, so complex objects can slow down performance substantially in published applications. Symbols should be used for elements appearing more than once, elements should be grouped, and timeline layers should separate elements that change from elements that do not.

Flash Player 10 and AIR 1.5 provided a new drawing API, which enables higher performance by reducing the amount of code execution. These functions include:

  • drawPath()
  • drawGraphicsData()
  • drawTriangles()

As noted, cacheAsBitmap can improve performance for translation; however, is redrawn when scaled or rotated.

Raster bitmap assets will almost always yield highest performance. Techniques such as blitting / bit blit and bitmap sprite sheets for animation will outperform vector drawing.

Within my apps, a technique I often implement is off-stage rendering of vector assets as shown in this StackOverflow post: AS3 Blitting - Copy Pixels getting some of the souce image.

Using this method vector assets may be scaled; however, only bitmaps are added to the display list.

Not specific to graphics rendering performance, it should be noted using Shape or Sprite would yield minor performance improvement over the dynamic MovieClip class.

Upvotes: 1

Related Questions