user547414
user547414

Reputation:

Drawing multiple Bitmaps onto a single Sprite in different locations

I have many base images that I need to combine to construct larger images to draw on Sprite objects. I understand that the beginBitmapFill() method of the Graphics class renders a bitmap on a Sprite's graphics object. So I figure that I need to manipulate the BitmapData object, adding the base images to produce a composite image that I can then draw on my Sprite.

My question is: Is there any clean and relatively hassle free way of doing this? Is there a way to draw Bitmaps to certain locations in a Sprites graphics context? Could you copy a Graphics object onto another at certain coordinates and build it that way?

Upvotes: 0

Views: 1503

Answers (1)

NoobsArePeople2
NoobsArePeople2

Reputation: 1996

How large are these large images you intend to construct? Flash 10 is limited to creating a bitmap of 8191x8191px (Flash 9 is limited to 2880x2880px). You can read more about it in the docs.

Assuming you're okay on the dimensions of your large image I would recommend you take the first approach you mentioned: copy the pixel data from the smaller bitmaps into one larger bitmap and then draw that into your Sprite's Graphics object.

I would do this by first creating a new BitmapData object at the large size and then looping over each of the smaller images and using BitmapData.copyPixels() to copy the pixels from each small bitmap into the large one. Once the large image is constructed you can use Graphics.beginBitmapFill() and Graphics.drawRect() to draw the large BitmapData into the Sprite.

The reason for going this route is that BitmapData.copyPixels() is going to be faster than Graphics.beginBitmapFill() and Graphics.drawRect(). It's also a lot cleaner looking since you'd have to do beginBitmapFill() for each new bitmap if you went that way.

Upvotes: 2

Related Questions