Skip to Main Content
Learning XNA 3.0
book

Learning XNA 3.0

by Aaron Reed
November 2008
Beginner content levelBeginner
510 pages
16h 24m
English
O'Reilly Media, Inc.
Content preview from Learning XNA 3.0

Modifying the Sprite Class

The first thing you'll need to do in the Sprite class is change the namespace of the class from AnimatedSprites to Catch:

namespace Catch

In this game, players will take turns chasing each other. There will be two sprite objects: a gears sprite and a dynamite sprite. The dynamite sprite will always chase the gears sprite around the screen. Because players will be switching back and forth from gears sprites to dynamite sprites, you'll need to expose a few variables with auto-implemented properties. To do this, add the following class-level variables to your Sprite class:

public Texture2D textureImage { get; set; }
public Point sheetSize { get; set; }
public Vector2 speed { get; set; }
public Vector2 originalSpeed { get; set; }

You're also going to need to set the positions of the sprites between rounds, so that the chaser and chased players don't start next to each other. Change the GetPosition property accessor to Position and add a set accessor:

public Vector2 Position
{
    get { return position; }
    set { position = value; }
}
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XNA 4.0

Learning XNA 4.0

Aaron Reed
Beginning C# 7 Programming with Visual Studio 2017

Beginning C# 7 Programming with Visual Studio 2017

Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid

Publisher Resources

ISBN: 9780596154905Supplemental ContentErrata Page