0
votes

I would like to use Bitmaps in my Actionscript games.

For me this represents a large change in my workflow as I have always used Vector but Bitmaps are really so much faster to render in certain circumstances. As far as I can see, 90% of all my game assets can be bitmaps.

Firstly, are there any good tools for working with Vector to BitmapData? Libraries or OpenSource utilities?

I know you can just draw to a BitmapData, and I do that, but what about Animations? What about a MovieClip of a laughing cow? How can I render that MovieClip at runtime to some kind of Bitmap version?

But more complex than that... What about situations where you do not have the MovieClip in a raw form?

Imagine 10000 cogs turning at the same rate which is generated with code. This is hard work for the processor, so drawing it to a Bitmap for the duration of 1 revolution, would replace 10000 cogs with a SpriteSheet. I could destroy the cogs, and keep the SpriteSheet.

Can anyone offer me any resources or google keywords I can search for, not sure of the technique but it seems to make sense? Especially with Starling..... My Vectors are going to have to become SpriteSheets at some point.

Thanks.

2

2 Answers

2
votes

The basic process of converting a movie clip to a sprite sheet is this:

  1. Choose a movieclip.
  2. Get the bounds of the movie clip. You need to get the width and height of the widest and tallest frame of animation.
  3. get the number of frames of the movie clip.
  4. Make a new bitmapdata object that as wide as the # of frames times the width of a frame. And as high as one frame. 5 loop through each frame of the clip, and call bitmapData.draw() on each frame. Be sure to offset the matrix of the draw command on each frame by the width of one sprite frame.

The end result will be a single bitmapdata object with each frame rendered to it.

From there you can follow this tutorial on blitting. http://www.8bitrocket.com/2008/07/02/tutorial-as3-the-basics-of-tile-sheet-animation-or-blitting/

1
votes

Converting spritesheets to bitmaps at runtime is not exactly a trivial task, and you may be better served to build your spritesheets before compilation, and use a framework with a blitting engine, such as Flixel or Flashpunk (I'm not very familiar with Starling, but that would work too, I presume). There are a couple decent MovieClip/SWF to png converters:

However, if you are intent on making spritesheets at runtime, you can probably repurpose some of the code from Zoe (it is open source). Take a look at the CaptureSWF class, particularly capture() and handleVariableCaptureFrames(). These methods are the meat of converting individual frames of a MC to BitmapData, which can then be used to build spritesheets.