Windows Phone 7 Development Tutorial (3)--xna using MessageBox and soft keyboard

Source: Internet
Author: User
Tags exit silverlight

I believe that I will be with XNA for the next spare time. Originally wanted to develop the depth of 3D development, but encountered a practical problem, is how to display the XNA under the MessageBox and software Input Panel. Just write it out first, so that you don't get mad when you meet the problem.

According to one of the few public document descriptions, XNA and Silverlight for Windows phone should be based on the CLR of the same. NET Compact framework. However, XNA does not provide any user controls, MessageBox, and soft keyboards, nor does it directly invoke the class library of Silverlight for Windows Phone. This is bound to create a lot of man-made obstacles for XNA. But calling MessageBox and software Input panel's back door, Xna still left us, this is the Guide class under the Microsoft.Xna.Framework.GamerServices namespace, the class description is as follows:

Http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.gamerservices.guide.aspx

This class can call not only MessageBox and soft keyboards, but also forms such as marketplace, XBox live, and so on. However, it is worth noting that the Guide class provides methods that are asynchronous, not synchronous, and it is understandable that the game is handled in a time-driven manner, so any operation should not block the main thread of the game.

Guide class calls the description of the MessageBox and the soft keyboard here:

Http://msdn.microsoft.com/en-us/library/ff827869.aspx

Http://msdn.microsoft.com/en-us/library/ff827868.aspx

However, there are some flaws in the MSDN documentation, which produces exception by the method provided above, so I'll give you a way to run the changes below. The operating environment is based on the VS + Windows Phone 7 SDK RTW Edition.

Call MessageBox

Create the project for XNA 4.0 in Windows Phone 7, and then we add a call to MessageBox in the Update method. Of course, please do not think that the MessageBox added to the update in the correct, this will cause MessageBox constantly pop up. I did it just to simplify the code.

protected override void Update (Gametime gametime)
{
allows the game to exit
if (gamepad.getstate (Playerindex.one). Buttons.back = = buttonstate.pressed)
This. Exit ();
Todo:add Your update logic here

Mboptions. ADD ("OK");
Mboptions. Add ("Cancel");
if (! guide.isvisible)
Guide.beginshowmessagebox ("Test", "Hello, XNA", mboptions, 0, Messageboxicon.alert, new AsyncCallback ( respcallback), null);
Base. Update (gametime);
}

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.