Dav*_*ott 2 android collision imageview
当两个ImageView相互交叉时,我正试图让事情发生.这是我使用的代码:
Rect rect1 = new Rect();
imageView.getHitRect(rect1);
Rect rect4 = new Rect();
imageView2.getHitRect(rect4);
boolean collision = false;
collision = rect1.intersect(rect4);
if(collision = true){
button.setText("collided");
}else
button.setText("not collided");
Run Code Online (Sandbox Code Playgroud)
但是,当应用程序启动时,布尔值才会更改为true.第一个ImageView保持静止,而另一个移动到第一个(它不是精灵,但是它朝着第一个ImageView的方向移动并移过它).我希望布尔值在两个ImageView相交时改变.有什么我想念的吗?
试试这个 :
Rect rc1 = new Rect();
imageView1.getDrawingRect(rc1);
Rect rc2 = new Rect();
imageView2.getDrawingRect(rc2);
if (Rect.intersects(rc1, rc2) {
// intersection is detected
// here is your method call
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3690 次 |
| 最近记录: |