XNa game: Landscape and portrait settings

Source: Internet
Author: User

There will be a portrait screen in the mobile phone device. Generally there are three situations: one is a portrait screen, the other is a right landscape screen, and the other is a left landscape screen, the landscape settings are set through the supportedorientations attribute of the graphicsdevicemanager class. The graphicsdevicemanager class mentioned in the xNa class library introduction is very important. It provides developers with methods to manage the graphics card resources of the target device. In short, it calls an interface of the video card. The graphicsdevice attribute of this object represents the video card of the current target device.

Example:

 Using  System;  Using  System. Collections. Generic;  Using  System. LINQ;  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. Input. Touch;  Using  Microsoft. xNa. Framework. Media;  Namespace  Rotationsample {  ///  <Summary>      ///  This is the main type for your game  ///   </Summary>      Public   Class  Game1: Microsoft. xNa. Framework. Game {graphicsdevicemanager graphics; spritebatch; spritefont rotationfont;  Public  Game1 () {graphics = New Graphicsdevicemanager ( This ); Content. rootdirectory = "  Content  "  ;  //  Frame rate is 30 FPS by default for Windows Phone. Targetelapsedtime = timespan. fromticks ( 333333  );  //  Add support for landscape and landscape screens Graphics. supportedorientations = displayorientation. Portrait | displayorientation. landscapeleft |Displayorientation. landscaperight ;}  ///   <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 Rotationfont = content. Load <spritefont> ( "  Rotationfont  "  );}  ///   <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 ();  Base  . Update (gametime );}  ///   <Summary>          ///  This is called when the game shoshould 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  Spritebatch. Begin (); spritebatch. drawstring (rotationfont,  "  Your current mobile phone status is:  " + Window. currentorientation. tostring () + "  .  " , New Vector2 ( 50 , 50  ), Color. White); spritebatch. End ();  Base  . Draw (gametime );}}} 

 

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.