title: C# XNA - randomly draw a texture on the top X axis
body: <p>So I'm making a space invaders game. I want to have meteors spawning from <code>different/random locations on the entire 0 coordinate of X</code>. How should I ahieve this? I've seen people using <code>Lists</code> and <code>Random()</code>s but I need a code for my <code>meteorGenerator</code> class. Then I'll call it's methods in Game1</p>
  
  <p>When the meteors are drawn they should fall down at the bottom of the screen and disappear.
  I saw an answer here on SO and implemented it to my class:</p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.Linq;
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Storage;
  using Microsoft.Xna.Framework.Audio;
  using Microsoft.Xna.Framework.Content;
  using Microsoft.Xna.Framework.GamerServices;
  using Microsoft.Xna.Framework.Graphics;
  using Microsoft.Xna.Framework.Input;
  using Microsoft.Xna.Framework.Media;
  using Microsoft.Xna.Framework.Net;
  
  namespace SpaceInvaders
  {
      class meteorGenerator
      {
          public static Vector2 m_Pos;
          public Vector2 m_Position
          {
              get { return m_Pos; }
              set { m_Pos = value; }
          }
          Texture2D m_Texture { get; set; }
          Texture2D m_MeteorsTex;
  
          public meteorGenerator(Texture2D m_Tex, Vector2 m_Pos)
          {
              m_Position = m_Pos;
              m_Texture = m_Tex;
          }
  
          List&lt;meteorGenerator&gt; m_MeteorsList = new List&lt;meteorGenerator&gt;();
  
          static readonly Random rnd = new Random();
  
          public void LoadContent(ContentManager Content)
          {
              m_MeteorsTex = Content.Load&lt;Texture2D&gt;(".\\gameGraphics\\gameSprites\\thePlan\\meteorSpawn");
          }
  
          public void Update(GameTime gameTime)
          {
              if (m_MeteorsList.Count() &lt; 4)
              {
                  m_MeteorsList.Add(new meteorGenerator(m_MeteorsTex, new Vector2(rnd.Next(30, 610), rnd.Next(30, 450))));
              }
          }
  
          public void Draw(SpriteBatch spriteBatch)
          {
              foreach (meteorGenerator m_Meteor in m_MeteorsList)
              {
                  spriteBatch.Draw(m_Meteor.m_Texture, m_Meteor.m_Position, Color.White);
              }
          }
  
      }
  }
  </code></pre>
  
  <p>But when I try to instance the constructor of the class in Game1 I get an error:</p>
  
  <pre><code>meteorGenerator m_MeteorGenerator;
  protected override void Initialize()
  {
      // TODO: Add your initialization logic here.
      m_MeteorGenerator = new meteorGenerator(meteorGenerator.m_Tex, meteorGenerator.m_Pos);
  }
  </code></pre>
  
  <p><code>Error  1   'SpaceInvaders.meteorGenerator' does not contain a definition for 'm_Tex'</code></p>