1

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?

Community
  • 1
  • 1
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
  • 2
    There should be no difference. The embedded SWF is still drawing the vectors using the same methods as you would using the Drawing API, even if it is drawn using the pen tool or similar. Vector graphics still have to be drawn. Using a Bitmap is much faster than vectors, but as you said, sometimes you can't use Bitmaps. – Josh Apr 30 '13 at 19:44
  • not directly relevant to your question, but you can set cacheAsBitmap=true on a movieclip to treat it as a Bitmap (for better rendering performance) –  Apr 30 '13 at 21:13

1 Answers1

1

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.

Community
  • 1
  • 1
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
  • Have you found it faster to add many Bitmap objects into the display list with paired BitmapDatas or add one Bitmap and use copyPixels manually to layout the objects you need? – Robin Rodricks May 02 '13 at 05:55
  • I keep static content drawn to a single instance, and use bitmaps for animated content. – Jason Sturges May 03 '13 at 19:53