XNA游戏:横竖屏设置

手机设备里面,会有横竖屏的状态,一般会有3种情况,一个中是竖屏,一个是右横屏,一个是左横屏,横屏的设置是通过GraphicsDeviceManager类的SupportedOrientations属性来设置的,GraphicsDeviceManager类在XNA类库介绍中提到的该类型是非常重要的。它为开发者提供方法来管理目标设备的显卡资源。简单地说就是调用显卡的一个接口,该对象的GraphicsDevice属性代表当前目标设备的显卡。

示例:

 

 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using Microsoft.Xna.Framework;  
  5. using Microsoft.Xna.Framework.Audio;  
  6. using Microsoft.Xna.Framework.Content;  
  7. using Microsoft.Xna.Framework.GamerServices;  
  8. using Microsoft.Xna.Framework.Graphics;  
  9. using Microsoft.Xna.Framework.Input;  
  10. using Microsoft.Xna.Framework.Input.Touch;  
  11. using Microsoft.Xna.Framework.Media;  
  12.  
  13. namespace RotationSample  
  14. {  
  15.     /// <summary> 
  16.     /// This is the main type for your game  
  17.     /// </summary> 
  18.     public class Game1 : Microsoft.Xna.Framework.Game  
  19.     {  
  20.         GraphicsDeviceManager graphics;  
  21.         SpriteBatch spriteBatch;  
  22.         SpriteFont rotationFont;  
  23.  
  24.         public Game1()  
  25.         {  
  26.             graphics = new GraphicsDeviceManager(this);  
  27.             Content.RootDirectory = "Content";  
  28.  
  29.             // Frame rate is 30 fps by default for Windows Phone.  
  30.             TargetElapsedTime = TimeSpan.FromTicks(333333);  
  31.             //添加横屏和竖屏的支持  
  32.             graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;  
  33.         }  
  34.  
  35.         /// <summary> 
  36.         /// Allows the game to perform any initialization it needs to before starting to run.  
  37.         /// This is where it can query for any required services and load any non-graphic  
  38.         /// related content.  Calling base.Initialize will enumerate through any components  
  39.         /// and initialize them as well.  
  40.         /// </summary> 
  41.         protected override void Initialize()  
  42.         {  
  43.             // TODO: Add your initialization logic here  
  44.  
  45.             base.Initialize();  
  46.         }  
  47.  
  48.         /// <summary> 
  49.         /// LoadContent will be called once per game and is the place to load  
  50.         /// all of your content.  
  51.         /// </summary> 
  52.         protected override void LoadContent()  
  53.         {  
  54.             // Create a new SpriteBatch, which can be used to draw textures.  
  55.             spriteBatch = new SpriteBatch(GraphicsDevice);  
  56.  
  57.             // TODO: use this.Content to load your game content here  
  58.             rotationFont = Content.Load<SpriteFont>("rotationFont");  
  59.         }  
  60.  
  61.         /// <summary> 
  62.         /// UnloadContent will be called once per game and is the place to unload  
  63.         /// all content.  
  64.         /// </summary> 
  65.         protected override void UnloadContent()  
  66.         {  
  67.             // TODO: Unload any non ContentManager content here  
  68.         }  
  69.  
  70.         /// <summary> 
  71.         /// Allows the game to run logic such as updating the world,  
  72.         /// checking for collisions, gathering input, and playing audio.  
  73.         /// </summary> 
  74.         /// <param name="gameTime">Provides a snapshot of timing values.</param> 
  75.         protected override void Update(GameTime gameTime)  
  76.         {  
  77.             // Allows the game to exit  
  78.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)  
  79.                 this.Exit();  
  80.  
  81.             base.Update(gameTime);  
  82.         }  
  83.  
  84.         /// <summary> 
  85.         /// This is called when the game should draw itself.  
  86.         /// </summary> 
  87.         /// <param name="gameTime">Provides a snapshot of timing values.</param> 
  88.         protected override void Draw(GameTime gameTime)  
  89.         {  
  90.             GraphicsDevice.Clear(Color.CornflowerBlue);  
  91.  
  92.             // TODO: Add your drawing code here  
  93.             spriteBatch.Begin();  
  94.             spriteBatch.DrawString(rotationFont, "你现在手机的摆放状态是:" + Window.CurrentOrientation.ToString() + ".", new Vector2(50, 50), Color.White);  
  95.             spriteBatch.End();  
  96.  
  97.             base.Draw(gameTime);  
  98.         }  
  99.     }  

 


本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1078391

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
2023华数全国大学生数学竞赛是由中国未来研究会大数据与数学型专业委员会、天津市未来与预测科学研究会大数据分会举办的国家级比赛。该比赛旨在培养大学生的创新意识和运用数学方法解决实际问的能力,并为创新性人才的培养奠定基础,为各行各业培养和选拔优秀人才。参赛作品将获得组委会详细的书面评价,并进行赛后数学技术辅导,以提高学生的数学水平。 比赛将在2023年8月4日(周四)18:00开始,持续到8月7日(周日)20:00。比赛结果将预计在2023年8月中下旬公布。参赛对象包括研究生组、本科生组和专科生组三个组别,每个队伍由1-3名大学生和最多1名指导教师组成。目一般来源于各行业实际问,经过简化形成,分为A、B、C三个目,难度和国赛数类似。比赛费用为每队200元,用于大赛组织、命、评审、专家指导等工作。 在比赛中,获得全国一等奖、二等奖、三等奖以及优秀奖的队伍将获得荣誉证书。此外,比赛还提供微信公众号“爱数的小驴需要助攻”的思路助攻服务,帮助参赛者更好地进行数学。 总之,2023华数全国大学生数学竞赛是一个具有较高含金量和规的国家级比赛,旨在培养大学生的科学精神和数学解决问的能力。参与这个比赛可以作为国赛前的拟比赛,对参赛队伍提供了全面的支持和指导。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [2023年华数数学](https://blog.csdn.net/m0_58496908/article/details/132069559)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [2023华数全国大学生数学竞赛思路代码](https://blog.csdn.net/weixin_45499067/article/details/131838529)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [2021华数全国大学生数学竞赛C1](https://download.csdn.net/download/weixin_35784267/86357964)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值