Saturday, September 03, 2011

Scaling Bitmaps In Flash ActionScript 3 (AS3)

I was working on composing large Bitmaps and scaling them and noticed an optimization that might have included a bug. The images I was scaling were pixel snapping and were not smoothed. This resulted in a choppy tween.

In the past avoiding choppy image animations required setting the quality to "best". Now ActionScript allows granular control of images. In my project they were embeded as external assets and pulled from a SWF file.


As of Flash Player version, when scaling Bitmaps in Flash smoothing and PixelSnapping are ignored when the scale is equal to 1. In order to force smooth set the Bitmap to a scale not equal to 1.0.

For example:
var bitmap:Bitmap = new Bitmap(_bitmapData, 'never', true);
bitmap.scaleX = bitmap.scaleY = .99;


John said...

I may possibly have this error in my custom tilemap code.
I've noticed it being a bit chopy. Though I was thinking the only
way to fix that was to make sure the background does not scroll too slowly.
-John Mark

Henry Tseng said...

John, you can have it scroll slowly. You'll just need to turn on higher rendering so that it can anti-alias subpixel level.