手机设备里面,会有横竖屏的状态,一般会有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. 设计模式之状态模块加观察者模式
  2. 数字万用表测量二极管、三极管
  3. C++求tree树的高度(附完整源码)
  4. 使用Spring提供Quartz来实现定时任务
  5. java学习(40):成员实例的定义和访问
  6. erp系统是什么东西
  7. python plot方法的使用_Python bokeh.plotting.figure.step()用法及代码示例
  8. Aaron Swartz Rewriting Reddit中关于web.py的创建思路
  9. 【POJ3608】Bridge Across Islands(旋转卡壳求两凸多边形的最短间距)
  10. chrome扩展程序_如何在20分钟内创建和发布Chrome扩展程序
  11. 一文读懂电感器的原理、结构、作用及分类
  12. 闲聊历史上的配角之赵高
  13. 入职阿里巴巴,阿里P7高级架构师需要哪些技术栈?
  14. 【读书随记】周末充电,学习Java更轻松(文末送书)
  15. 美国计算机视觉专业排名,你了解美国计算机视觉专业吗
  16. postman上一接口返回值作为下一接口传参
  17. 云周刊】第177期:马云见证!蚂蚁金服推出全球首个区块链跨境汇款服务
  18. Java实现第九届蓝桥杯缩位求和
  19. 异步复位同步释放 打两拍
  20. 大数定理的MATLAB编程,用MATLAB模拟大数定律和中心极限定理.pdf

热门文章

  1. 堆排序-排序-数据结构和算法
  2. CF400D Dima and Bacteria(并查集+Floyd)
  3. python之torchlight使用_Unity3D加载火炬之光资源
  4. 徐志摩的《再别康桥》
  5. 频繁默认网关不可用_win10系统默认网关不可用频繁掉线的具体方法
  6. AnalyticDB向量化引擎
  7. 银河麒麟Kylin_s10_sp2安装Oracle11g(FS)(亲测有效)
  8. 2年时间,涨薪20k,想拿高薪还真不能老老实实的工作...
  9. 广州企业品牌网站建设和网站改版的大趋势
  10. 【信息安全第三章同余习题】把剩余类1(mod 5)写成模15的剩余类之和