hitTest BitMap,scaleX = +1和scaleX = -1

时间:2019-05-02 14:27:06

标签: actionscript-3 flash flash-cs6

我希望Player2与Player2匹配,因为BitMap和scaleX = 1和scaleX = -1在一起。使用scaleX = +1可以,但是使用 scaleX = -1,那么hitTest与我想要的不一样。有人可以帮我吗。

var Player2_Bmp:BitmapData = new BitmapData(Player2.width, Player2.height, true, 0);
var Player2_Rect:Rectangle = Player2.getBounds(Player2);
var Player2_Matrix:Matrix = new Matrix();
Player2_Matrix.translate(-Player2_Rect.x, -Player2_Rect.y)
Player2_Bmp.draw(Player2, Player2_Matrix);

var Player1_Bmp:BitmapData = new BitmapData(Player1.width, Player1.height, true, 0);
var Player1_Rect:Rectangle = Player1.getBounds(Player1);
var Player1_Matrix:Matrix = new Matrix();
Player1_Matrix.translate(-Player1_Rect.x, -Player1_Rect.y);

Player1_Bmp.draw(Player1, Player1_Matrix);

if(Player1_Bmp.hitTest(new Point(Player1_Rect.x + Player1.x, Player1_Rect.y + Player1.y), 255, 
             Player2_Bmp, new Point(Player2_Rect.x + Player2.x, Player2_Rect.y + Player2.y), 255))
{
    hit.text = String("Hit");
}
else
{
    hit.text = String("Not Hit");
}

0 个答案:

没有答案