Windows Phone 7 programming practices-xNa

Source: Internet
Author: User
We useMsdnUpperUsing a basic effect with texturing Introduction XNa game 4.0Texturedquad_sampleExample, Describes howWindowsRunning onXNaProgramQuick deploymentWindows Phone 7Mobile phone andThe Xbox 360Test and run.
Objective: To develop a practical manual for Windows Phone 7
Windows Phone 7 programming practices References: Programming Windows Phone 7
Msdn library -- Windows Phone development
UI design and interaction guide for Windows Phone 7 V2.0
Designing Web sites for phone browsers
Develop for Windows Phone & Xbox 360 code sample Windows Phone 7 Application certification requirements
In the course of this book, we strive to explain the development technology of Windows Phone in depth and different aspects. As personal abilities and levels need to be improved, the analysis of many problems is still superficial. Please give us your advice and suggestions for improvement. Directory
Preface Texturedquad program description
Description in msdn
Running results on Windows
Transformed into a Windows Phone 7 program Generate a new Windows Phone 7 Project
Running results in Windows Phone 7 Simulator CodeHas it actually changed? Game1.cs Program. CS Secrets Preface
XNa is the main development method of Windows Phone 7 in terms of applications and games, XNa originated from the game world's well-known DirectX, and is Microsoft's revised and expanded version of C # DirectX.
If you have previously worked on xNa in windows and Xbox 360, you are lucky because the xNa programs you have previously worked on will be easily deployed on Windows Phone 7 mobile phones, there is almost no need to change the code. What an incredible thing has been said that no program can run on all operating systems.
We useMsdnUpperUsing a basic effect with texturing Introduction XNa game 4.0Texturedquad_sampleExample, Describes howWindowsRunning onXNaQuickly deploy programsWindows Phone 7Mobile phone andThe Xbox 360Test and run.
Special thanks to Microsoft technical experts Bruce Wang gave me a wonderful explanation on the teched cloud computing tour of Qingdao station in China, which gave me the xNa features. You can write down this article Article . Texturedquad program description
Description in msdn
Using a basic effect with texturing
Http://msdn.microsoft.com/en-us/library/bb464051.aspx Demonstrates how to create and draw a simple quad-two triangles that form a rectangle or square-using Drawuserindexedprimitives.
This sample introducesQuadClass, which is used to construct a quad with a list of vertices and indices suitable for drawing with drawuserindexedprimitives. the sample also demonstrates how to use basiceffect to render the quad and to apply a texture to the primitive. for more information about basiceffect, see creating a basic effect.

The code in the topic shows you the technique for creating and drawing a quad. you can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
Download texturedquad_sample.zip .
Running results on Windows
Here, let's not talk about the functions implemented by the program itself. Next we will not manually modify the code to port this program to Windows Phone 7 and Xbox 360. The premise is that you have installed Windows Phone 7 for vs2010 in your system to develop all the environments and Development kits. Here, we will not describe the installation process. Transformed into a Windows Phone 7 program
Generate a new Windows Phone 7 Project
In [Solution Explorer], select the "texturedquadwindows" project and right-click it, for example, [Create copy of project for Windows Phone], vs2010 will automatically create a project running on Windows Phone for us. For example. [Windows Phone copy of texturedquadwindows] is a project generated by the system and can run on Windows Phone. Next, we will change the project name to texturedquadwindowsphone and set it to the default startup program. Running results in Windows Phone 7 Simulator
Re-compile the program and run debug in the simulator of Windows Phone 7. The result is as follows: has the code changed?
Has the code changed? The answer is no. Take a closer look at the xuanjicang of game1.cs and program. CS files. Game1.cs
Check that the update method found in game1.cs contains" # IfWindows " InWindowsThe program will processKeyboard.
///
<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
VoidUpdate (GametimeGametime)
{

// Allows the game to exit

If(Gamepad. Getstate (Playerindex. One). Buttons. Back =Buttonstate. Pressed)

This. Exit ();
# IfWindows

If(Keyboard. Getstate (). iskeydown (Keys. Escape ))

This. Exit ();
# Endif

// Todo: add your update logic here

Base. Update (gametime );
}
Program. CS
In the program. CS file, we found" # IfWindows | Xbox " .
NamespaceTexturedquadwindows
{
# IfWindows | Xbox

Static
Class
Program
{

///
<Summary>

///The main entry point for the application.

///
</Summary>

Static
VoidMain (String[] ARGs)
{

Using(Game1Game =New
Game1())
{
Game. Run ();
}
}
}
# Endif
}
Secrets
In fact, game1.cs and program. cs used in the texturedquadwindows project and texturedquadwindowsphone, and the files required for running other programs are the same, but why are there no obstacles in the porting process. The porting problem has been taken into account when writing the original program. # IfWindows

If(Keyboard. Getstate (). iskeydown (Keys. Escape ))

This. Exit ();
# Endif
In program. CS # IfWindows | Xbox

Static
Class
Program
{

///
<Summary>

///The main entry point for the application.

///
</Summary>

Static
VoidMain (String[] ARGs)
{

Using(Game1Game =New
Game1())
{
Game. Run ();
}
}
}
# Endif
The original program has been divided based on different hardware features of windows, Windows Phone, and Xbox 360. Therefore, we achieved it overnight through Dongfeng during the transplantation process. To sum up, we should also pay attention to this feature when writing xNa programs, and write well" # IfWindows "And" # IfWindows | Xbox ", Easy to transplant the program, easy to transform. The method for converting the original program into a program running on Xbox 360 is the same. Try it on your own.
Related Article

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.