<< Chapter < Page Chapter >> Page >
Learn how to design and create a Sprite class that provides collision detection. Also learn how to write an XNA program that takes advantage of that collision detection capability.

Revised: Mon May 09 18:37:13 CDT 2016

This page is part of a Book titled XNA Game Studio .

Table of Contents

Preface

This module is one in a collection of modules designed primarily for teaching GAME 1343 Game and Simulation Programming I at Austin Community College in Austin, TX. These modules are intended tosupplement and not to replace the textbook.

An earlier module titled Getting Started provided information on how to get started programming with Microsoft's XNA Game Studio.

Viewing tip

I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the Figuresand Listings while you are reading about them.

Figures

  • Figure 1 . Screen output at three different times while the program was running.

Listings

  • Listing 1 . A new Image property accessor method in the Sprite class.
  • Listing 2 . A modified constructor.
  • Listing 3 . A modified SetImage method.
  • Listing 4 . A new method named GetRectangle.
  • Listing 5 . Beginning of a new IsCollision method.
  • Listing 6 . Test for a collision with other sprites.
  • Listing 7 . Beginning of the overridden LoadContent method of the Game1 class.
  • Listing 8 . Instantiate the spider and ladybug Sprite objects.
  • Listing 9 . Beginning of the overridden Update method.
  • Listing 10 . Beginning of a for loop that controls the collision testing.
  • Listing 11 . Test for a collision.
  • Listing 12 . Spiders don't die easily.
  • Listing 13 . The overridden Game.Draw method.
  • Listing 14 . The Sprite class for the project named XNA0130Proj.
  • Listing 15 . The Game1 class for the project named XNA0130Proj.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Xna game studio. OpenStax CNX. Feb 28, 2014 Download for free at https://legacy.cnx.org/content/col11634/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Xna game studio' conversation and receive update notifications?

Ask