私はmonogameと私のヒット検出にいくつかの問題を抱えて私はポンゲームを作成しようとしています。私はボールが左のパドルに当たったときにボールを方向転換させたいが、何らかの理由で衝突が唯一のものではなく上で検出されるので、ボールはパドルの側面を通過するが、トップに当たるとバウンスする私は間違って何をしていますか? HERESに私のコードMonogame衝突検出が正しく動作しません
バットクラスの一部
public class Bat : DrawableGameComponent
{
private SpriteBatch spriteBatch;
private Texture2D tex;
private Vector2 speed;
private Vector2 position;
private Vector2 stage;
public Rectangle Rectangle
{
get
{
return new Rectangle((int)position.X, (int)position.Y, tex.Width, tex.Height);
}
}
public Bat(Game game,
SpriteBatch spriteBatch,
Texture2D tex,
Vector2 position,
Vector2 speed,
Vector2 stage): base(game)
{
this.spriteBatch = spriteBatch;
this.tex = tex;
this.position = position;
this.speed = speed;
this.stage = stage;
}
衝突クラス更新方法
public override void Update(GameTime gameTime)
{
if (ball.Rectangle.Intersects(bat.Rectangle))
{
ball.speed.Y = -Math.Abs(ball.speed.Y);
hitSound.Play();
}
base.Update(gameTime);
}
とBATと衝突検出
Texture2D batTex = this.Content.Load<Texture2D>("Images/BatLeft");
Vector2 batPos = new Vector2(100,100);
Vector2 batSpeed = new Vector2(4, 0);
bat = new Bat(this, spriteBatch, batTex, batPos, batSpeed, stage);
this.Components.Add(bat);
SoundEffect dingSound = this.Content.Load<SoundEffect>("Music/ding");
CollisionDetection cd = new CollisionDetection(this, ball, bat, dingSound);
this.Components.Add(cd);
、バットとボールの矩形が(あなたが 'Rectangle'クラスの代わりに、独自の変数を使用している)に定義されていない、標準として長方形を使用してみてくださいgetメソッドを持たない変数。すぐに公共の変数から呼び出します。 – Steven
ここでも円と四角形の衝突が必要です。 –