I wrote a collision detection class that works using BitmapData.hitTest. Basically, each update, the .draw method is called, and then two BitmapData hitTest'ed against each other to see if there is a collision.
This works very well, however, if I start to rotate the original MovieClip that I use for BitmapData, the transforms are not logged in the draw method. So what I did was go through the Matrix in the drawing method. It works. But here is the actual problem . If I output BitmapData to a bitmap on the scene, I can see that Bitmap is actually rotating, but now it exceeds the boundaries (width and height) of BitmapData. Which crop / crop the image of the original MovieClip.
My first guess would be to rotate BitmapData, but rotation is not possible. There are no properties to help you remove this. Is there another way?
UPDATE . In principle, when a Bitmap MovieClip clone rotates outside the positive coordinate space, it cannot be drawn. It rotates beyond the boundaries of the width and height of BitmapData. I can multiply the borders by 2, and then center the bitmap inside the set borders, but then the start point is never fixed, and the object always moves. It works very well, but makes it impossible to align the object to any specific point.
Here is my isolated test code. This requires that you have a MovieClip on the stage called "iTest". I used a rather vertical arrow shape (above the width), so I could visually track rotations and help emphasize 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
{
if (this.getChildByName("iTestClone") != null)
{
removeChild(this.getChildByName("iTestClone"));
testClone = null;
testData = null;
}
iTest.rotation += 1;
var testData:BitmapData = new BitmapData(iTest.width, iTest.height, false, 0xFFFFFF);
var testMatrix:Matrix = new Matrix();
testMatrix.scale(iTest.scaleX, iTest.scaleY);
testMatrix.rotate( iTest.rotation * (Math.PI / 180) );
testMatrix.translate(0, 0);
testData.draw(iTest, testMatrix);
var testClone:Bitmap = new Bitmap(testData);
testClone.name = "iTestClone";
testClone.transform = testMatrix.tra
addChild(testClone);
this.swapChildren(iTest, testClone);
}
rotateObject_init();