Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is...
-
Upload
hester-stevenson -
Category
Documents
-
view
214 -
download
2
Transcript of Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is...
Rob Miles
How does an XNA game program work?
• Programs tell computers what to do• A program is written in a programming
language– C# is a programming language
• XNA is a framework that provides program resources for writing games
• Programs describe Data and the Actions that are performed on it
Computer Games and Programs• A Computer Game is a program
that plays a game with us• All computer game programs
work in the same way– Load all the pictures, sounds and
models• Update the game world• Draw the game world• Repeat as fast as possible
• This is true whether the game is GTA IV, Pac Man or The Sims
The Anatomy of Program
• A program contains two things• A description of the Data it
works with– Like a list of ingredients for a
recipe for a cake• A description of the actions
that the program should perform on the data– Like the steps to perform to
make the cake
Data
Actions
The Anatomy of an XNA Game
• In an XNA program the data describes the “game world”
• The actions describe how to update and draw the world– Update moves items around,
detects collisions etc– Draw produces a view of the
world for the player to see
Game Data
Update action
Draw action
Other actions...
Computer Games and XNA
• The Update and Draw behaviours in an XNA game are expressed as methods
• When you make a new game XNA creates a template game file with empty Draw and Update methods for you to fill in
• Here is an empty XNA game with no graphics
• This is the starting point for every game
• It just draws a blue screen
Empty Game
Performing Actions in Programs• A C# statement is a single step
in a program– Like an action in a recipe : “Turn
on oven”– Each statement is separated
from the next by a semi-colon• A C# method is a number of
statements in a block which have been given a name– Like an entire set of steps: “Boil
the kettle”
The XNA Draw method
• A method is a block of C# with a particular name• The DrawDraw method draws the game display• Above is the method you get with a new game• The most important part has been shaded
protected override void Draw(GameTime gameTime){ graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);}
protected override void Draw(GameTime gameTime){ graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);}
How Clear Works
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
The graphics device manager
The graphics device itself
The Clear method
The Colour value to use, in this caseit is a kind of blue
Making Sense of a Method Call
backBedroom.SatelliteTV.SwitchChannel(Channel.BBC);backBedroom.SatelliteTV.SwitchChannel(Channel.BBC);
Something that holds items
The item we want to use
The instruction we want obeyed
Information for the instruction
A Different Colour
graphics.GraphicsDevice.Clear(Color.Red);graphics.GraphicsDevice.Clear(Color.Red);
The graphics device manager
The graphics device itself
The Clear method
The Color value to use, in this caseit is red
• We can modify the call of Clear in the Draw method
• It is told the colour to clear the screen
• We can change that colour
Yellow Screen
• A program contains data and actions• Two of the actions in an XNA game program are
the ones that Update the game and Draw the screen
• An “empty” XNA game contains a Draw method that draws a blue screen using a Clear method
• We can change the colour of the screen by changing the information sent into the Clear method
• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear
the screen• There is a colour called Teal
• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear
the screen• There is a colour called Teal
• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear
the screen• There is a colour called Teal
• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear
the screen• There is a colour called Teal
• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear
the screen• There is a colour called Teal
• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear
the screen• There is a colour called Teal
• XNA games do not use data• A method is a block of code with a name• Your program must call the Draw method• The C# language contains the Clear method• The Clear method is told the colour to clear
the screen• There is a colour called Teal