XNA GameStudio 2.0
Drawing The Ball On Screen

Just as we created a class to put all of the details of the bat in one place, we do the same for the ball.

Setting Up A Ball Class

Study the following code carefully, before adding a class called Ball.cs to your project. Remember to set this new class up in a similar way to the Bat.cs class - copy the using statements to the top of the code window.

class Ball
{
   public Texture2D sprite;
   public Vector2 position;
   public Vector2 velocity;
   public Ball(Texture2D loadedTexture)
   {
      position = Vector2.Zero;
      sprite = loadedTexture;
      velocity = Vector2.Zero;
   }
   public void Update()
   {
      position += velocity;
   }
}

Drawing The Ball On Screen

The steps we follow to make sure that the ball is on the screen are very similar to what we have done before.

Start by adding the following field to the list near the top of the Game1.cs class.

Ball ball;

We set up the ball with two statements in the LoadContent() method of the Game1.cs class.

ball = new Ball(Content.Load<Texture2D>("Sprites\\ball"));
ball.position = new Vector2(400.0f - ball.sprite.Width / 2, 300.0f - ball.sprite.Height / 2);

Finally, we add a statement to the Draw() method so that the ball is drawn on the screen.

spriteBatch.Draw(ball.sprite, ball.position, Color.White);

Test that the ball appears correctly on the screen - somewhere close to the centre spot is what you are looking for.