<< Chapter < Page Chapter >> Page >
Learn how to move your sprite. Also learn how to use methods of the Debug class.

Revised: Sun May 08 09:19:08 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

Listings

  • Listing 1 . Skeleton code for a new Windows Game project.
  • Listing 2 . Declare variables that specify the incremental distance to move.
  • Listing 3 . Beginning of the overridden Update method.
  • Listing 4 . Test for sprite out of bounds horizontally.
  • Listing 5 . Test for sprite out of bounds vertically.
  • Listing 6 . Change the current position of the sprite.
  • Listing 7 . The remainder of the overridden Update method.
  • Listing 8 . Overridden LoadContent method.
  • Listing 9 . The class named Game1 for the project named XNA0120Proj.

General background information

The earlier module titled Xna0118-The XNA Framework and the Game Class used a very simple XNA program to teach many of the details regarding the incorporation ofthe XNA framework into the object-oriented C# programming language.

Skeleton code

When you create a new Windows Game project using Visual C#, a source code file named Game1.cs is automatically created and opened in the editor window. The file contains skeleton code for a windows gamebased on XNA. Listing 1 shows the skeleton code contained in the file named Game1 (with most of the comments deleted for brevity).

Listing 1 . Skeleton code for a new Windows Game project.

using System; using System.Collections.Generic;using System.Linq; using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics;using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media;namespace WindowsGame2 {public class Game1 : Microsoft.Xna.Framework.Game {GraphicsDeviceManager graphics; SpriteBatch spriteBatch;public Game1() {graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content";} protected override void Initialize(){ // TODO: Add your initialization logic herebase.Initialize(); }protected override void LoadContent() {// Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice);// TODO: use this.Content to load your game content here }protected override void UnloadContent() {// TODO: Unload any non ContentManager content here }protected override void Update(GameTime gameTime) {// Allows the game to exit if(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed)this.Exit(); // TODO: Add your update logic herebase.Update(gameTime); }protected override void Draw(GameTime gameTime) {GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code herebase.Draw(gameTime); }} }

Questions & Answers

how do you get the 2/50
Abba Reply
number of sport play by 50 student construct discrete data
Aminu Reply
width of the frangebany leaves on how to write a introduction
Theresa Reply
Solve the mean of variance
Veronica Reply
Step 1: Find the mean. To find the mean, add up all the scores, then divide them by the number of scores. ... Step 2: Find each score's deviation from the mean. ... Step 3: Square each deviation from the mean. ... Step 4: Find the sum of squares. ... Step 5: Divide the sum of squares by n – 1 or N.
kenneth
what is error
Yakuba Reply
Is mistake done to something
Vutshila
Hy
anas
hy
What is the life teble
anas
hy
Jibrin
statistics is the analyzing of data
Tajudeen Reply
what is statics?
Zelalem Reply
how do you calculate mean
Gloria Reply
diveving the sum if all values
Shaynaynay
let A1,A2 and A3 events be independent,show that (A1)^c, (A2)^c and (A3)^c are independent?
Fisaye Reply
what is statistics
Akhisani Reply
data collected all over the world
Shaynaynay
construct a less than and more than table
Imad Reply
The sample of 16 students is taken. The average age in the sample was 22 years with astandard deviation of 6 years. Construct a 95% confidence interval for the age of the population.
Aschalew Reply
Bhartdarshan' is an internet-based travel agency wherein customer can see videos of the cities they plant to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400 a. what is the probability of getting more than 12,000 hits? b. what is the probability of getting fewer than 9,000 hits?
Akshay Reply
Bhartdarshan'is an internet-based travel agency wherein customer can see videos of the cities they plan to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400. a. What is the probability of getting more than 12,000 hits
Akshay
1
Bright
Sorry i want to learn more about this question
Bright
Someone help
Bright
a= 0.20233 b=0.3384
Sufiyan
a
Shaynaynay
How do I interpret level of significance?
Mohd Reply
It depends on your business problem or in Machine Learning you could use ROC- AUC cruve to decide the threshold value
Shivam
how skewness and kurtosis are used in statistics
Owen Reply
yes what is it
Taneeya
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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