Archive for November, 2008
Caching Animation Frames VS Spritesheets
Friday, November 28th, 2008Apparantly drawing each frame of an animation to a single bitmap and then selecting a region to display is better for memory and speed than keeping each frame in its own bitmapData object.
The issue i’ve had is that for larger animations a sprite sheet of 2880×2880 is a little restrictive. To counter this ive modified bit101’s BigAssCanvas to allow a copyPixels of a rect, in order to get our frame data from a BIG Sprite sheet. This makes the test a little unfair, but small spritesheets are not an option for us.
The results are as follows:
uncached: ~16fps
cached as frames: ~120fps
cached on spritesheet: ~70fps
memory usage:
frames: 249 856
spritesheet: 270 336
so caching each frame seems the way to go for us. There doesnt seem to be any advantage in the spritesheet. It might run faster if it was a single bitmapData object and direct coptyPixels – but who’s to say
Posted in Flash | 14 Comments »
CopyPixels for BigAssCanvas
Friday, November 28th, 2008We needed to copy out the BitmapData from a BigAssCanvas so i added this to bit101s class. It doesnt really work like BitmapData's copyPixels - as that copys pixel INTO the bitmap object, so i've named it copyPixelsOut and it returns a new bitmapData of the rect.
You will notice the red lines at 2880 when you move the viewable region over them the data you are given is atually sourced from 2 bitmapData objects (inside the BigAssBitmap).
PS: Thanks to Jonno from Something Splendid for helping me when my maths brain had disappeared.
Its basically :
-
public function copyPixelsOut(rect:Rectangle, transparent:Boolean=true, fillColor:uint=0xff000000 ):BitmapData
-
{
-
var bitmapData:BitmapData = new BitmapData(rect.width, rect.height, transparent, fillColor);
-
-
for(var i:int = 0; i <_bitmaps.length; i++)
-
{
-
var bmp:Bitmap = _bitmaps[i] as Bitmap;
-
var temp:Rectangle = rect.clone();
-
temp.x -= bmp.x;
-
temp.y -= bmp.y;
-
-
if(temp.intersects(new Rectangle(0,0,2880,2880))){
-
bitmapData.copyPixels(bmp.bitmapData, temp, new Point());
-
}
-
}
-
-
return bitmapData;
-
}
Posted in Flash | 1 Comment »
Flash: Normal Mapping for Physics
Wednesday, November 26th, 2008Almost a year ago I was reading about how normal mapping works (on Wikipedia I think) and it struck me that this would be a great way to define a useful height map for games, maybe a mini golf game as an example.
My understanding is that normal maps work by encoding the X and Y angle difference from a flat surface (generally a polygon). That is the difference between a larger polygon from a low count polygon model, and the multiple polygons that made up a high count polygon model. This is normally saved as red and green channels. The blue channel (from what I could work out) was used in some way for height (or Z).
Posted in Flash | 8 Comments »