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.