开发者

Converting Sprite to bitmapdata with a different registration point and rotation

I'm trying to convert a Sprite that I have into BitmapData so I can perform some collision detection. There are a few things about the way the Sprites are used that is making this more difficult than I expected:

  • The Sprite itself is a container which holds another Sprite that actually has a box drawn in it. The inner Sprite is positioned negative half its width & height so that it can be rotated from the center via the container.
  • The container may be rotated at any angle at any given time

So my approach thus far has been attempting to draw the outer Sprite onto a new BitmapData object with a Matrix to account for the difference. Whilst I can use a Matrix to make this work for one particular rotation angle, I c开发者_如何学Goannot find a way to make it work for any rotation.

Here's what I'm doing to draw onto the new BitmapData:

var p:Product = getProduct(); // Product is the container with the inner sprite
var bounds:Rectangle = p.getBounds(stage);
var bd:BitmapData = new BitmapData(bounds.width, bounds.height, true, 0x00FFFFFF);

var m:Matrix = p.transform.matrix;
// Somewhere here is what needs to be changed, I can't figure out how though
m.tx = 0;
m.ty = 0;

bd.draw(p, m);

With m.tx = 0 & m.ty = 0, here is an example of what I get and what I want to get:

Converting Sprite to bitmapdata with a different registration point and rotation

The yellow image on the right is the actual box, with the black outline being the "container" that gets rotated. The image on the left is what I get for the BitmapData, where I want the yellow box to not be cut off. In this example, I could just translate tx and ty by half the width and height, which would work.

A better example would be once it's actually rotated:

Converting Sprite to bitmapdata with a different registration point and rotation

Translating by the same amount as the previous example will no longer work here, and the box will still be cut off. I've looked around at some solutions posted before or suggestions from other people but they don't seem to work for me due to my container Sprite and rotation.

I'd very much appreciate any help on this issue.

Thanks!


try replacing

m.tx = 0;
m.ty = 0

with

m.tx = -bounds.x;
m.ty = -bounds.y;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜