Xna4.0 Reading Notes 1. Basic Structure of xNa

Source: Internet
Author: User
Basic Structure of game classes
After creating an xNa program, there are 5 Functions in game1.cs
Initialize (): used to initialize variables and related objects.
Loadcontent (): used to load images and other content to be loaded.
Update (): update content
Draw (): draw an image
Unloadcontent (): it is executed when the program ends and is used to uninstall related content.
 
The relationship between the five functions is as follows: the main content is a loop of update () and draw (). The update method is executed either in the game loop.
The draw method is then called. Either the game ends, the game loop is exited, And the unloadcontent method is called.
 
 
 
There are two Defined variables in the. CS file.
        GraphicsDeviceManager graphics;        SpriteBatch spriteBatch; 
Graphicsdevicemanager is used to access graphics devices.
Spritebatch is used to draw the core object of the genie
 
In the UPDATE function, there is a sentence
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)               this.Exit();

This is the way to judge the game's end

 

In the draw function,

GraphicsDevice.Clear(Color.CornflowerBlue);

Clear the screen. Clear the screen and fill it with blue

 

The input parameters in update and draw are

GameTime gameTime

Used to identify the time that passes through the game. This variable helps us determine the time when the animation and other time occur more realistically than the processor speed.

 

Engineering documents

In the project we created, we can see two projects, one is the project file we created <myproject>, and the other is named

<Myprojectcontent> Project

All resources (graphics, sounds, models) used in the game should be added to the xxxcontent project.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.