XNa preparation (1)

Source: Internet
Author: User

Please exit this page. Thank you...

I believe many people know about Xbox. How is the Xbox game developed? Let's learn about this Xbox game development together.

First, prepare the development-related development tool xna3.0.

After xna3.0 is installed, it is automatically appended to the Project template of vs2008 development tool.

 

Let's start the game:

I installed vs2008 development tool.

First, open vs2008 ---> Create a project ---> Expand the Visual C # Node ---> xNa game studio3.0 (this is the powerful guy) ---> Windows game (3.0) {why should I choose this one? Because I have no money to buy xbox .......}, create a project named "myfirstgame.

 

XNa automatically creates a template for you.

 

1. Check the project's program. CS file.

 
Static class program {// <summary> // the main entry point for the application. /// </Summary> static void main (string [] ARGs) {using (game1 game = new game1 () {game. run ();}}}

I believe I have writtenProgramEveryone knows what this means. Here is the entry to the myfirstgame program.

 

2. Follow the prompts at the program portal to check the game1.cs FileCode.

Using system; using system. collections. generic; 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; using Microsoft. xNa. framework. net; using Microsoft. xNa. framework. storage; namespace myfirstgame {// <summary> // This is the main type for your game /// </Summary> public class game1: Microsoft. xNa. framework. game {graphicsdevicemanager graphics; spritebatch; Public game1 () {graphics = new graphicsdevicemanager (this); content. rootdirectory = "content";} // <summary> // allows the game to perform any initialization it needs to before starting to run. /// this is where it can query for any required services and load any non-graphic // related content. calling base. initialize will enumerate through any components // and initialize them as well. /// </Summary> protected override void initialize () {// todo: add your initialization logic here base. initialize ();} // <summary> // loadcontent will be called once per game and is the place to load // all of your content. /// </Summary> 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} // <summary> // unloadcontent will be called once per game and is the place to unload // all content. /// </Summary> protected override void unloadcontent () {// todo: unload any non contentmanager content here} // <summary> // allows the game to run logic such as updating the world, // checking for collisions, gathering input, and playing audio. /// </Summary> /// <Param name = "gametime"> provides a snapshot of timing values. </param> protected override void Update (gametime) {// allows the game to exit if (gamepad. getstate (playerindex. one ). buttons. back = buttonstate. pressed) This. exit (); // todo: add your update logic here base. update (gametime);} // <summary> // This is called when the game shocould draw itself. /// </Summary> /// <Param name = "gametime"> provides a snapshot of timing values. </param> protected override void draw (gametime) {graphicsdevice. clear (color. cornflowerblue); // todo: add your drawing code here base. draw (gametime );}}}

 

After reading the above Code, if you are dizzy, we suggest you exit this page.

 

I will give a rough description of these methods one by one.

1. First, we must inherit Microsoft. xNa. Framework. game. Don't ask why, so we are definitely correct, as if we continue to form when writing winform. It contains game events, functions, attributes, and so on.

2. game1 (): it is the constructor. Is this person's name very familiar? By the way, it is in program. something in the CS file. Here, it mainly refers to some necessary information of the initialization program.

3. initialize (): this overload function initializes some controls.

4. loadcontent (): The game content is loaded.

5. unloadcontent (): called when the game form is closed.

6. Update (gametime): The program will constantly update operations, mainly reflecting the relationship between the Update Time of game content, if you need to constantly update the screen or sound of the game, this is the most recent implementation.

7. Draw (gametime): used to draw a graph. It takes the update time parameter.

 

Next, let's draw a graph of the function here. It is very important to do a good job of relationship. If there is a problem with the graph I have drawn, please correct me. Let's learn and improve it together.

 

Relationship diagram:

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.