0

こんにちは、私はこれらのベクトルを持っています:

    Vector2 ground1p1 = new Vector2(0,430);
    Vector2 ground1p2 = new Vector2(200,430);
    Vector2 ground1p3 = new Vector2(0, 290);
    Vector2 ground1p4 = new Vector2(280, 340);

私はそれらをリストに入れたいので、これを行う代わりに:

if (DetectPlayerAndGround1Collision2(playerPosition,ground1p1,player,ground1) == true)
            {
                hasJumped = false;
                velocity.Y = 0f;
            }
            if (DetectPlayerAndGround1Collision2(playerPosition, ground1p2, player, ground1) == true)
            {
                hasJumped = false;
                velocity.Y = 0f;
            }

これは、書き込みの最後に「ベクトル」を書き込むときの問題です。リストとして宣言していないように何も起こりません。

 public class Game1 : Microsoft.Xna.Framework.Game
     {

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;




        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }


        protected override void Initialize()
        {

            base.Initialize();
        }


        bool hasJumped = true;


        Vector2 velocity;
        Texture2D player;
        Texture2D ground1;
        List<Vector2> vectors = new List<Vector2>();


        Vector2 playerPosition = new Vector2(30, 300);
        Vector2 ground1p1 = new Vector2(0,430);
        Vector2 ground1p2 = new Vector2(200,430);
        Vector2 ground1p3 = new Vector2(0, 290);
        Vector2 ground1p4 = new Vector2(280, 340);
4

1 に答える 1

1

リストを使用できます(提案したように)

List<Vector2> vectors = new List<Vector2>();

vectors.Add(ground1p1);
vectors.Add(ground1p2);
vectors.Add(ground1p3);
vectors.Add(ground1p4);

foreach (Vector2 vec2 in vectors) 
{
    if (DetectPlayerAndGround1Collision2(playerPosition, vec2, player, ground1))
    {
        hasJumped = false;
        velocity.Y = 0f;         

        // maybe add a break to prevent superfluous calls
        break;
    }
}
于 2012-12-03T18:10:31.957 に答える