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

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

XNA游戏:横竖屏设置相关推荐

  1. statusBarOrientation设备状态判断--- 横竖屏设置

    在一般的视频类APP播放的时候都会支持横屏,这样做的好处就是便于观看.你的项目中支持横屏吗?我们一起了解一下,在iOS9中横竖屏设置的处理方法吧! 简单说明: UIInterfaceOrientati ...

  2. Android横竖屏设置

    默认情况下,当用户手机的"屏幕旋转"选项打开后,旋转手机方向,手机屏幕也会跟随旋转的方向进行横竖屏切换. 设置屏幕旋转的方式有两种: 一.在AndroidManifest.xml设 ...

  3. iOS开发:App横竖屏设置问题

    在iOS开发中,难免会遇到关于手机屏幕是否切换横竖屏的问题,比如一个App整体的界面都需要竖屏显示,那么只用在Xcode里面的General里面的Deployment Info里面把横竖屏选项勾选去掉 ...

  4. flutter 横竖屏设置

    import 'package:flutter/services.dart'; void main(){// 强制横屏SystemChrome.setPreferredOrientations([De ...

  5. Win7游戏全屏设置

    你的系统是win7的吧!改下就行了-- 搜索框输入 regedit 定位到 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsD ...

  6. Activity 横竖屏切换

    前言 在开发中常要处理横竖屏切换,怎么处理先看生命周期 申明 Activity 横竖屏切换时需要回调两个函数 ,所以在此将这个两个函数暂时看成是Activity 横竖屏切换的生命周期的一部分,这两个函 ...

  7. android虚拟机固定横屏幕竖屏,用VBox虚拟机安装Android 屏幕90度翻转竖屏设置

    在虚拟机中安装好Android之后,有一些Android应用(比如UC浏览器.UC桌面)不能安装.但更有一些程序是可以安装,却自动顺时间旋转了90度,操作和看起来非常不爽! 这个情况下,在Androi ...

  8. 移动端判断手机横竖屏状态

    禁用用户自动缩放功能: <meta name="viewport" content="width=device-width, initial-scale=1.0, ...

  9. android 横竖屏幕切换,Android 横竖屏切换总结

    一.Android切换横竖屏 应用的横竖屏设置 应用的横竖屏设置主要是通过Activity的screenOrientation属性控制,属性值如下: 主要有以下两种方式设置screenOrientat ...

最新文章

  1. HBase应用快速学习
  2. jQuery对象插件封装步骤
  3. [linux]centos7下解决yum install mysql-server没有可用包
  4. react 组件连动效果_React组件开发中常见的陷阱
  5. 怒卸python3.4.1
  6. SAP Cloud for Customer里根据External Reference搜索销售订单
  7. 计算机网络上网时间,电脑怎么限制上网时间
  8. [阅读笔记]Zhang Y. 3D Information Extraction Based on GPU.2010.
  9. 《大道至简》周爱民读后感
  10. 14 递归函数、二分法
  11. Mysql orangepi_orangepi4安装gogs
  12. TensorFlow 入门 | iBooker·ApacheCN
  13. mybatis的xml文件 比较详细的学习注意点
  14. django - 修改 自增长id,起始值
  15. python真好玩 pdf_编程真好玩(青少年学Python一本通)
  16. android 连线题实现 自定义view  画线
  17. 软件评测师考试通过啦
  18. TcaplusDB X 光与夜之恋|春暖花开之际与你相遇
  19. 黑盒、白盒和灰盒测试的区别
  20. 我觉得,我认为。。。

热门文章

  1. Scenario和Scenario Outline的区别
  2. STDOJ 木木不哭┭┮﹏┭┮(DP)
  3. win7下微软自带语音识别的系统命令(二)
  4. 中国量子计算机应用普及,15年后量子计算机或可普及,你相信吗?
  5. 前端通过vue获取浏览器类型和版本最新
  6. 华为机试-求int型数据在内存中存储时1的个数
  7. msf使用木马控制android手机
  8. linux软中断通信的基本原理,实验三 软中断通信
  9. 结构体中重载大于小于号用于排序
  10. 浅谈密码学的历史发展过程