<< Chapter < Page
  Xna game studio     Page 4 / 8
Chapter >> Page >

The parameters and the body

The parameters required by this method and the body of the method are the same as for the first constructor discussed above.

The Draw method of the Sprite class

Listing 4 shows the Draw method of the Sprite class in its entirety.

Listing 4 . The Draw method of the Sprite class.

public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture,position,Color.White);}//end Draw method //-------------------------------------------------//}//end Sprite class }//end namespace

This method should be called after a call to the SpriteBatch.Begin method and before a call to the SpriteBatch.End method.

A single parameter

The method requires a single parameter, which is a reference to the SpriteBatch object on which the Begin method has been called.

The body of the Sprite.Draw method

You should recognize the single statement in the method as a call to the simplest available Draw method belonging to the SpriteBatch object. This version of the SpriteBatch.Draw method allows the caller to specify

  • The texture or image to be drawn.
  • The position in the game window relative to the upper left corner of the window at which the image will be drawn.
  • A color tint that will be applied to the image with White being no change in color.

The end of the class

Listing 4 signals the end of the Sprite class.

The Game1 class

Methods of the Game1 class were overridden to demonstrate the use of the Sprite class to produce the output described earlier .

The class named Game1 begins in Listing 5 .

Listing 5 . Beginning of the class named Game1.

namespace XNA0126Proj { public class Game1 : Microsoft.Xna.Framework.Game {GraphicsDeviceManager graphics; SpriteBatch spriteBatch;//References to the Sprite objects are stored in this // List object.List<Sprite>sprites = new List<Sprite>(); int maxSprites = 24;//Max number of sprites.int frameCnt = 0;//Game loop frame counter //This is the limit on the number of frames in which// the sprites are moved. int moveLim = 200;

Listing 5 simply declares several instance variables, most of which you should recognize. The others are well described by the comments. However,one of the instance variables, sprites , introduces a concept that is new to this module.

The generic List class

Listing 5 declares a variable named sprites and populates it with a reference to a new generic List object that is conditioned to store and retrieve references to objects of the class Sprite .

Here is some of what the documentation has to say about the generic List class:

"Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists."

The generic List class provides many more capabilities than I will use in this program. I will use an object of the generic List class to store references to Sprite objects that I can later access using a zero-based index. This will eliminate the requirement to declarea separate reference variable for each of the Sprite objects that I instantiate.

The modified Game1 constructor

The constructor for the Game1 class was modified to set the size of the game window as shown in Listing 6 .

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
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