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 ...

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.