我已经发布了一个关于此主题的问题..但没有得到答案。我正在做一个游戏。在那个应用程序中,我必须检测画布中两个对象的碰撞。对象类粘贴在这里。Android中两个对象的碰撞检测
public class Droid {
private Bitmap bitmap; // the actual bitmap
private int x; // the X coordinate
private int y; // the Y coordinate
private boolean touched; // if droid is touched/picked up
private Speed speed; // the speed with its directions
public Droid(Bitmap bitmap, int x, int y) {
this.bitmap = bitmap;
this.x = x;
this.y = y;
this.speed = new Speed();
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public boolean isTouched() {
return touched;
}
public void setTouched(boolean touched) {
this.touched = touched;
}
public Speed getSpeed() {
return speed;
}
public void setSpeed(Speed speed) {
this.speed = speed;
}
public void draw(Canvas canvas) {
canvas.drawBitmap(bitmap, x - (bitmap.getWidth()/2), y - (bitmap.getHeight()/2), null);
}
/**
* Method which updates the droid's internal state every tick
*/
public void update() {
if (!touched) {
x += (speed.getXv() * speed.getxDirection());
y += (speed.getYv() * speed.getyDirection());
}
}
/**
* Handles the {@link MotionEvent.ACTION_DOWN} event. If the event happens on the
* bitmap surface then the touched state is set to <code>true</code> otherwise to <code>false</code>
* @param eventX - the event's X coordinate
* @param eventY - the event's Y coordinate
*/
public void handleActionDown(int eventX, int eventY) {
if (eventX >= (x - bitmap.getWidth()/2) && (eventX <= (x + bitmap.getWidth()/2))) {
if (eventY >= (y - bitmap.getHeight()/2) && (y <= (y + bitmap.getHeight()/2))) {
// droid touched
setTouched(true);
} else {
setTouched(false);
}
} else {
setTouched(false);
}
}
}
我正在创建5个droid对象。其中4人不断在画布上移动,1人由用户控制。我想要检测这4个移动物体与用户控制对象发生碰撞的事件。我已经阅读了许多教程,但还没有得到解决方案。请帮助我的人...
没有人为此问题提供答案?????? :( –
使用AndEngine进行游戏会更好。 –