views:

961

answers:

4

I have a bitmap loaded in flash, for a 2D game. The bitmap represents a character and is rotating when the user uses the A (left) or D (right) keys. The problem I have is that the border of the image becomes ugly while rotating, you can see "pixels" (you can always see pixels, but I hope you understand what I mean).

How can I fix this in actionscript 3, maybe change the rotation algorithm or "fix" the image after rotation? Or should I save/render the image differently in eg. Photoshop before using it with Flash?

Update: note that the background of the game is constantly changing.

Thanks in advance.

+1  A: 

You could try a simple antialias along the edges by summing the pixel that is there and the pixel you will be overlaying. You could take a look at Wu antialiasing for an example you could use as a start point.

graham.reeds
this is really the nuclear option. there's really no need to do this in something like flash that's basically made to scale and rotate stuff.
grapefrukt
I'm not a flash programmer - since the OP was asking I didn't think there was an library function that would do that for you.
graham.reeds
+3  A: 

If the image is an external load (Loader class), then you can write:

Bitmap(myLoader.content).smoothing=true;

If it's internal (its in the library) you need to right click the library bitmap > properties and enable "Smoothing". Plus, if you are instantiating it as a BitmapData, then you need to do this:

var bmp:BitmapData=new LibraryBitmap(0,0);
var bitmap:Bitmap=new Bitmap(bmp,"auto",true); //the third argument is smoothing

Cheers...

Cay
+3  A: 

use the flash.display.Bitmap::smoothing property ... the langref specifies, it smooth's when scaling, but it works for rotation as well ...

back2dos
+1  A: 

A quick note: Bitmap rotation is slow, so while loading the game, it might be a good idea to take characters that are often rotating, or are common, rotate them to every 1 degree that is possible in the game, use BitmapData.draw, and push it onto an Array (or a Vector in FP10, if possible), and then use those Bitmaps.

YAY, run-on sentences!

Happy Coding! :-)

PiPeep