title: XNA drawing and creating an array of objects
body: <p>Hi all I am trying to create a game, and right now, I have a balloon class, which I want to currently create an amount of them via an array, and then draw then into the game. </p>
  
  <p>Currently however it seems it is either only creating one instance of balloon or only drawing 1 instance. I'v looked over it multiple times, and from what I understand it should be looping through the entire array size (currently set at 10) and creating that many balloons, then updating and drawing that many. </p>
  
  <p>Are you not able to do what I am currently doing with an array? Would I have to create each object sparately? </p>
  
  <p>Here is the code of the two classes concerned.</p>
  
  <p>GameLevel:
  The class that creates the onjects and draws them.</p>
  
  <pre><code>        public partial class GameLevel : GameScreen
          {
              SpriteBatch spriteBatch;
              protected Game game;
  
              Texture2D balloonTexture;
  
              Balloon[] balloons = new Balloon[10];
  
              public GameLevel(Game game, SpriteBatch spriteBatch)
                  : base(game, spriteBatch)
              {
                  this.game = game;
                  this.spriteBatch = spriteBatch;
              }
  
              public void LoadContent()
              {
  
                  for (int i = 0; i &lt; balloons.Length; i++)
                  {
  
  
  
                      int colour;
                      Random random = new Random();
  
  
                      colour = random.Next(1, 6);
  
                      switch (colour)
                      {
                          case 1: balloonTexture = Game.Content.Load&lt;Texture2D&gt;("Images/BlueBalloon");
                              break;
                          case 2: balloonTexture = Game.Content.Load&lt;Texture2D&gt;("Images/RedBalloon");
                              break;
                          case 3: balloonTexture = Game.Content.Load&lt;Texture2D&gt;("Images/YellowBalloon");
                              break;
                          case 4: balloonTexture = Game.Content.Load&lt;Texture2D&gt;("Images/GreenBalloon");
                              break;
                          case 5: balloonTexture = Game.Content.Load&lt;Texture2D&gt;("Images/PurpleBalloon");
                              break;
                      }
                      balloons[i] = new Balloon(new Rectangle(0, 0, 1152, 648), balloonTexture);
                      balloons[i].SetStartPosition();
                  }
              }
  
              public void Update()
              {
  
                  for (int i = 0; i &lt; balloons.Length; i++)
                  {
                      balloons[i].Update();
                  }
  
  
              }
  
  
  
              public override void Draw(GameTime gameTime)
              {
                  for (int i = 0; i &lt; balloons.Length; i++)
                  {
  
                      balloons[i].Draw(spriteBatch);
                  }
  
                  base.Draw(gameTime);
              }
          }
      }
  </code></pre>
  
  <p>Ballon Class:</p>
  
  <pre><code>    public class Balloon
      {
  
          Vector2 position;
          Vector2 motion;   
          Rectangle bounds;
          Rectangle screenBounds;
          public Texture2D texture;
          float balloonSpeed = 4;
  
          public Balloon(Rectangle screenBounds, Texture2D texture)     
          {       
              this.texture = texture;
              this.screenBounds = screenBounds;
          }
  
          public Rectangle Bounds
          {
              get
              {
                  bounds.X = (int)position.X;
                  bounds.Y = (int)position.Y;
                  return bounds;
              }
          }
  
  
          public void Update()
          {
              position += motion * balloonSpeed;
          }
  
          private void CheckWallColision()
          {
              if (position.X &lt; 0)
              {
                  position.X = 0;
                  motion.X *= -1;
              }
  
              if (position.X + texture.Width &gt; screenBounds.Width)
              {
                  position.X = screenBounds.Width - texture.Width;
                  motion.X *= -1;
              }
  
              if (position.Y &lt; 0)
              {
                  position.Y = 0;
                  motion.Y *= -1;
              }
  
              if (position.Y + texture.Height &gt; screenBounds.Height)
              {
  
                  position.Y = screenBounds.Height - texture.Height;
                  motion.Y *= -1;
              }
          }
  
          public void SetStartPosition()
          {
              Random rand = new Random();
  
              motion = new Vector2(rand.Next(2, 6), -rand.Next(2, 6));
              motion.Normalize();
  
              position = new Vector2(rand.Next(100, 500), rand.Next(100, 500));
  
          }
  
  
          public void Draw(SpriteBatch spriteBatch)
          {
              spriteBatch.Draw(texture, position, Color.White);
  
          }
      }
  }
  </code></pre>