こんにちはみんな私はあなたが私を助けることができることを願っています。ゲームをコーディングしようとしましたが、衝突に失敗しました。たくさん検索したところ、バウンディングボックス方式(スプライトの周りに見えない長方形を作成する方法)が私にとって最良の解決策であることがわかりました。しかし、intersectメソッドは私には機能しません。衝突する2つのビットマップスプライトがありますが、LogCatでは衝突はありません...
スプライトNo.1クラス
public Sprite(GameView theGameView, Bitmap bmp) {
this.theGameView = theGameView;
this.bmp = bmp;
this.width = bmp.getWidth();
this.height = bmp.getHeight();
ySpeed = 0;
xSpeed = 1;
}
public Rect bounds() {
return (new Rect(x,y,width,height));
}
public void onDraw(Canvas canvas) {
canvas.drawBitmap(bmp, x, y, null);
}
スプライトNo.2クラス
public FourthSprite(GameView theGameView, Bitmap bmp) {
this.theGameView = theGameView;
this.bmp = bmp;
this.width = bmp.getWidth();
this.height = bmp.getHeight();
ySpeed = 0;
xSpeed = -1;
}
public Rect bounds() {
// TODO Auto-generated method stub
return (new Rect(x,y,width,height));
}
public void onDraw(Canvas canvas) {
canvas.drawBitmap(bmp, x, y, null);
}
}
GameViewクラス
public voidcollision(){
Rect r1 = theSprite.bounds(); // Sprite on left side
Rect r4 = theSprite4.bounds(); // Sprite on right side
if (r1.intersect(r4)){
collision = true;
Log.v("Log Tag", "COLLISION :D :D :D :D :D :D :D");
}
else {
collision = false;
Log.v("Log Tag", "NO COLLISION");
}
}
それが助けになるなら、私はビデオをアップロードすることもできます。
編集: http: //youtu.be/wYxZ7nKsmdw 1つのスプライトが動き回らず、x、y座標が0の場合、衝突が機能していることがわかりました。問題は何でしょうか。