私はそれを使用して停止し、代わりに、私は
自分の数学を使用し、ここでのコードは、誰かがそれ
public bool Intersects(Vector2 texture1, Vector2 textureSize1, Vector2 texture2, Vector2 textureSize2)
{
if (texture1.X < texture2.X + textureSize2.Y && texture1.X + textureSize1.X > texture2.X && texture1.Y < texture2.Y + textureSize2.Y && texture1.Y + textureSize1.Y > texture2.Y) return true;
return false;
}
public Block IsColliding(Vector2 position, float width, float height)
{
foreach (Block block in currentWorld.blocks)
{
if (Intersects(position, new Vector2(width, height), block.position, new Vector2(block.texture.Bounds.Width, block.texture.Bounds.Height))) return block;
}
return null;
}
たい場合は、最初のベクトル2(位置)プレーヤーの位置です。2つの浮動小数点は、プレーヤーテクスチャの幅と高さです(player.texture.Bounds.Width/Height)
「Intersects」のオーバーロードが見つかりません[https://msdn.microsoft.com /en-us/library/microsoft.xna.framework.rectangle.intersects.aspx]にはTexture2Dと 'Rectangle'があります。また、オブジェクトのメソッドを呼び出すと、そのオブジェクトをパラメータとして渡すことは奇妙に思われます。これはあなたが使用している_exact_コードですか? –
今すぐコードをチェックして、何かを偶発的に追加しました – Ahmedm
デバッガで実行して、衝突していないときの四角形の境界線を確認しましたか? –