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

Chapter 3. User Input and Collision Detection

As cool as it was to see a nice-looking set of rings spinning around and realize that you'd made that happen yourself, there's a long way to go with XNA. While the animated object looked nice, it didn't do anything, and you had no control over its movement. What fun is a game where there's no interaction on the part of the player? In this chapter, we'll explore user input and collision detection as ways to make your game actually do something besides look nice and pretty.

This chapter uses the code that you built at the end of Chapter 2 (the animated three rings sprite). Open that project and make the changes discussed in this chapter there.

More Sprites

If you're going to have a user-controlled object and build in some collision detection against other objects, you're going to need at least one more object on the screen. Let's add another animated sprite to your project.

Instead of using the same three rings image, we'll use a different image for the second animated sprite. Along with the source code for this book, you'll find the code for this chapter. In the AnimatedSprites\AnimatedSprites\Content\Images folder, you'll find an image called skullball.png. Add that image file to the project the same way you've added previous image files (right-click the Content\Images folder in Solution Explorer and select Add → Existing Item, then browse to the skullball.png image and add it to the solution).

Next, you'll need to create a number of variables ...

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