Android的ImageView的碰撞检测? [英] Android ImageView Collision Detection?
本文介绍了Android的ImageView的碰撞检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做出点什么,当两个ImageViews彼此相交。这是code,我用:
I'm trying to make something happen when two ImageViews intersect each other. This is the code that I used:
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");
不过,布尔刚换到真正的应用程序启动时。第一ImageView的保持静止,而另一移向第一个(它不是一个子画面,但它的动作中的第一个的ImageView的方向和移动经过它)。我想布尔值,当两个ImageViews相交改变。有我丢失的东西?
However, the boolean just changed to true when the app starts. The first ImageView stays still while the other moves towards the first one (it's not a sprite, but it moves in the direction of the first ImageView and moves past it). I want the boolean to change when the two ImageViews intersect. Is there something I'm missing?
推荐答案
试试这个:
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
}
这篇关于Android的ImageView的碰撞检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文