士兵级
centerX += speedX;
r.set(centerX , centerY, 50, 50);
子弹级
centerX += speedX;
r.set(centerX, centerY, 50, 50);
if(Rect.intersects(r,GameScreen.soldier.r))
{
System.out.println("collision");
}
我在碰撞检测方面遇到问题。我尝试过 Rect.intersects、r.intersect(r1)、r.contains(r1) 并且总是 false。我什至绘制了矩形以确保它们被正确绘制,但碰撞总是错误的
/**
* Check if two rectangles collide
* x_1, y_1, width_1, and height_1 define the boundaries of the first rectangle
* x_2, y_2, width_2, and height_2 define the boundaries of the second rectangle
*/
boolean rectangle_collision(float x_1, float y_1, float width_1, float height_1, float x_2, float y_2, float width_2, float height_2)
{
return !(x_1 > x_2+width_2 || x_1+width_1 < x_2 || y_1 > y_2+height_2 || y_1+height_1 < y_2);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)