Android旋转矩形与碰撞

时间:2014-09-26 19:01:09

标签: android canvas rotation collision rect

我想在Canvas上旋转一个Rectangle,但如果我用canvas.rotate()旋转它;并检查与rect1.intersect(rect2)的碰撞,它不会检查新旋转的Rect的碰撞,但是未旋转的Rect的碰撞。请帮助:)我的代码旋转并绘制矩形:

canvas.save();
roto = new RectF(-1, (int)height / 2 - (int)height / 20, (int)width + 1, (int)height / 2 + (int)height / 20);
if(rotation == true){
    canvas.rotate(degrees, width / 2, height / 2);
    degrees+=4f;
}
canvas.drawRect(roto, paint);
canvas.restore();

并检查碰撞:

RectF cursor1 = new RectF((int) event.getX(),
            (int) event.getY(), (int) event.getX() + 1,
            (int) event.getY() + 1);

if(cursor1.intersect(game.roto.roto) && play == true){
    game.roto.collision = true;
}

提前致谢:)

0 个答案:

没有答案