title: Game lagging (beginner)
body: <p>I am creating a game in which asteroids spawn and move down the screen. In the update method of the game, i am using a random number to spawn the asteroids sporatically. When i start it up, it begins to lag within the first 5 seconds. I can see this because the score counter(which goes up every tick) starts going in intervals of 30. Also, the images of the asteroid do not even show up. </p>
  
  <p>Here is the gameObject class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Microsoft.Xna.Framework;
  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;  
  using Microsoft.Xna.Framework.Storage;
  
  
  namespace thedodger
  {
  public abstract class gameObject
  {
      public static Texture2D texture;
      public Rectangle rectangle;
  
      public abstract void Draw(SpriteBatch spriteBatch);
      public abstract void Update(GameTime gameTime);
  }
  } 
  </code></pre>
  
  <p>here is the asteroid class;</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Microsoft.Xna.Framework;
  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;
  using Microsoft.Xna.Framework.Storage;
  
  namespace thedodger
  {
  public class Asteroid : gameObject
  {
      Random rand = new Random(1);
      int yPos = -10;
  
      public override void Draw(SpriteBatch spriteBatch)
      {
          spriteBatch.Begin();
          spriteBatch.Draw(texture, new Rectangle(rand.Next(32,400),      yPos,32,32),Color.White);
          spriteBatch.End();
  
      }
  
      public override void Update(GameTime gameTime)
      {
          yPos--;
  
  
      }
  }
  }
  </code></pre>
  
  <p>and here is the game1 class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using Microsoft.Xna.Framework;
  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;
  using Microsoft.Xna.Framework.Storage;
  
  namespace thedodger
  {
  /// &lt;summary&gt;
  /// This is the main type for your game
  /// &lt;/summary&gt;
  public class Game1 : Microsoft.Xna.Framework.Game
  {
      GraphicsDeviceManager graphics;
      SpriteBatch spriteBatch;
      int scorevalue = 0;
      SpriteFont font;
      player player1 = new player();
      List&lt;gameObject&gt; objectList = new List&lt;gameObject&gt;();
      Random rand = new Random(1);
      Asteroid asteroid = new Asteroid();
  
  
      public Game1()
      {
          graphics = new GraphicsDeviceManager(this);
          Content.RootDirectory = "Content";
      }
  
      /// &lt;summary&gt;
      /// Allows the game to perform any initialization it needs to before starting to run.
      /// This is where it can query for any required services and load any non-graphic
      /// related content.  Calling base.Initialize will enumerate through any components
      /// and initialize them as well.
      /// &lt;/summary&gt;
      protected override void Initialize()
      {
          // TODO: Add your initialization logic here
  
          base.Initialize();
      }
  
      /// &lt;summary&gt;
      /// LoadContent will be called once per game and is the place to load
      /// all of your content.
      /// &lt;/summary&gt;
      protected override void LoadContent()
      {
          // Create a new SpriteBatch, which can be used to draw textures.
          spriteBatch = new SpriteBatch(GraphicsDevice);
          font = Content.Load&lt;SpriteFont&gt;("font");
          //player1.image = Content.Load&lt;Texture2D&gt;("EnemyShip005.png");
          gameObject.texture = Content.Load&lt;Texture2D&gt;("asteroid");
  
          // TODO: use this.Content to load your game content here
      }
  
      /// &lt;summary&gt;
      /// UnloadContent will be called once per game and is the place to unload
      /// all content.
      /// &lt;/summary&gt;
      protected override void UnloadContent()
      {
          // TODO: Unload any non ContentManager content here
      }
  
      /// &lt;summary&gt;
      /// Allows the game to run logic such as updating the world,
      /// checking for collisions, gathering input, and playing audio.
      /// &lt;/summary&gt;
      /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt;
      protected override void Update(GameTime gameTime)
      {
          scorevalue++;
  
          if (rand.Next(0, 8) == 2)
          {
              for (int i = 0; i &lt; 30; i++)
              {
  
                  objectList.Add(asteroid);
  
  
              }
          }
  
          foreach (Asteroid asteroid in objectList)
          {
              asteroid.Update(gameTime);
              asteroid.Draw(spriteBatch);
          }
  
  
  
          // Allows the game to exit
          if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
              this.Exit();
  
          // TODO: Add your update logic here
  
          base.Update(gameTime);
      }
  
      /// &lt;summary&gt;
      /// This is called when the game should draw itself.
      /// &lt;/summary&gt;
      /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt;
      protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Color.CornflowerBlue);
  
          // TODO: Add your drawing code here
           spriteBatch.Begin();
           spriteBatch.DrawString(font, "Score: " + scorevalue, new Vector2(5, 5), Color.White);
           spriteBatch.End();
  
  
  
          base.Draw(gameTime);
      }
  }
  }
  </code></pre>
  
  <p>All help would be greatly appreciated.
  sorry about the code. I am having difficult setting it up. Help on that too please.</p>