3
\$\begingroup\$

What would be the fastest method for doing anti-aliasing for a flash game that is drawn via blitting to a BitmapObject?

A method I thought of would be to make games stage smaller than the BitmapObject that the game is drawn to, and then somehow shrink it to the size of the stage.

Would that method work? If so what would be the fastest and highest quality to shrink the bitmap? Or would there be a completely different way to do it?

\$\endgroup\$

3 Answers 3

3
\$\begingroup\$

The simple way is to let Flash do the bitmap resampling for you. Rather than composing the scene with blitting, make a movable object an individual Bitmap added to a parent DisplayObject, give the Bitmap fractional x,y coordinates, and set its pixelSnapping to NEVER. (The default for pixelSnapping is AUTO, which means Flash will round to int coordinates when the Bitmap's scale is close enough to 1.0, which I think is for aesthetic reasons as well as performance.)

I don't know how fast this dynamic resampling will be in arbitrary conditions. You should try it for your case and see if it's fast enough. One complication: I think Flash will use the GPU for this when it can, so simple tests may be misleading.

The much-more-work-but-maybe-faster way is to precompute resampled Bitmaps, like for one Bitmap, generate 16 Bitmaps, one for every .25 pixel offset in the x/y directions, and then blit whichever one is closest to the subpixel position.

\$\endgroup\$
3
  • \$\begingroup\$ Processor vs. Memory, the perennial struggle. \$\endgroup\$
    – Ipsquiggle
    Sep 4, 2010 at 16:39
  • \$\begingroup\$ I think I could use 4 different versions for each sprite. One for each half pixel in each direction. So it will use 4 times the data and not 16 times. \$\endgroup\$ Sep 4, 2010 at 20:54
  • \$\begingroup\$ No actually it would be 9 versions of each sprite \$\endgroup\$ Oct 10, 2010 at 17:38
1
\$\begingroup\$

I think that would work, and that you'd need to make your bitmap twice the screen size (or a higher integer multiplier) for the best quality.

However, that means you have to either draw everything scaled (so no copyPixels) or just work with larger source bitmaps (larger file, more memory usage), and you might be losing more performance than blitting is giving you.

\$\endgroup\$
1
\$\begingroup\$

I believe that you could add a Bitmap to the stage that is twice the size of the stage, set its scalex and scaley to 0.5, and then blit to its BitmapObject. I'm not sure how the performance would work out on it.

I'm a bit confused as to why you need antialiasing at runtime, though. Can't you antialias your bitmap resources beforehand, and just blit them directly, with alpha merge if necessary?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I want the movement to be smooth on the sub-pixel level. Blitting can only draw to whole pixels. So if I shrink it, it should give me less choppy movement. \$\endgroup\$ Sep 3, 2010 at 23:55
  • \$\begingroup\$ This is effectively what subsampling does anyways (only less naively). 0.5 will give you 2x AA, 0.25 will give you 4x, etc. \$\endgroup\$
    – Ipsquiggle
    Sep 4, 2010 at 0:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .