I wrote a collision detection class that works off using BitmapData.hitTest. Basically, every update, the .draw method is called and then two BitmapData's are hitTest'ed against each other to see if there is a collision.
It works pretty well, however if I start rotating the source MovieClip I use for the BitmapData, the transformations don't get registered in the draw method. So what I did was pass through a Matrix in the draw method. That works. But here's the actual issue. If I output the BitmapData to a Bitmap on the stage, I see that Bitmap is, in fact, rotating, but now it's exceeding the bounds (width and height) of the BitmapData. Which is cropping / clipping the image of the source MovieClip.
My first guess would be to rotate the BitmapData, but rotation doesn't seem possible. There's just no properties that help you pull that off. Is there another way?
UPDATE: Basically, when the Bitmap clone of the MovieClip rotates outside the positive co-ordinate space, it doesn't get drawn. It rotates outside the bounds of the BitmapData set width and height. I can multiply the bounds by 2, and then center the bitmap inside the set bounds, but then the origin point is never fixed and the object is always being moved around. Works pretty well, but makes aligning the object to any specific point impossible.
Here's my isolated test code. It requires you to have a MovieClip on the stage named "iTest". I used a fairly vertical arrow shape (higher than it is wide) so I could keep track of rotations visually and help accentuate the clipping problem:
var rotateTimer:Timer = new Timer(10);
function rotateObject_init():void
{
rotateTimer.addEventListener(TimerEvent.TIMER, rotateObject);
rotateTimer.start();
}
function rotateObject_stop():void
{
rotateTimer.removeEventListener(TimerEvent.TIMER, rotateObject);
rotateTimer.stop();
}
function rotateObject(_event:TimerEvent):void
{
// Deletes the previous bitmap
if (this.getChildByName("iTestClone") != null)
{
removeChild(this.getChildByName("iTestClone"));
testClone = null;
testData = null;
}
iTest.rotation += 1;
// Capture source BitmapData
var testData:BitmapData = new BitmapData(iTest.width, iTest.height, false, 0xFFFFFF);
// Capture source transformations
var testMatrix:Matrix = new Matrix();
testMatrix.scale(iTest.scaleX, iTest.scaleY);
testMatrix.rotate( iTest.rotation * (Math.PI / 180) );
testMatrix.translate(0, 0);
// Draw source with matrix
testData.draw(iTest, testMatrix);
// Output Bitmap
var testClone:Bitmap = new Bitmap(testData);
testClone.name = "iTestClone";
testClone.transform = testMatrix.tra
addChild(testClone);
// Always makes sure source is visible
this.swapChildren(iTest, testClone);
}
rotateObject_init();