[英]Collision detection between two images
I have 2 images, image A and image B. I want to know when image A moves to B and collides, how to detect this? 我有两个图像,图像A和图像B。我想知道图像A移动到B并碰撞时,如何检测到它?
This is my code: 这是我的代码:
case MotionEvent.ACTION_MOVE:
builder.append("move, ");
if (mode == DRAG)
{
matrix.set(savedMatrix);
// create the transformation in the matrix of points
matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
builder.setLength(0);
builder.append(event.getX());
builder.append("x , y ");
builder.append(event.getY());
text = builder.toString();
Log.d("TouchTest", text);
txtimage = (TextView)findViewById(R.id.txt);
txtimage.setText(text);
float aX = event.getX();
float aY = event.getY();
String a = Float.toString(aX);
String b = Float.toString(aY);
if (image.getWidth()/2 == image2.getWidth()/2 &&
image.getHeight()/2 == image2.getHeight()/2)
{
Toast.makeText(Multi_touchActivity.this, "collision",
Toast.LENGTH_SHORT).show();
}
}
您可以使用Rect相交方法检查它们是否确实重叠(碰撞)。
在大多数基于Java的图形引擎中,都有一种命中测试方法,尽管您将必须弄清楚此代码库究竟调用了什么-在图形库上搜索命中测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.