XNA游戏:横竖屏设置
手机设备里面,会有横竖屏的状态,一般会有3种情况,一个中是竖屏,一个是右横屏,一个是左横屏,横屏的设置是通过GraphicsDeviceManager类的SupportedOrientations属性来设置的,GraphicsDeviceManager类在XNA类库介绍中提到的该类型是非常重要的。它为开发者提供方法来管理目标设备的显卡资源。简单地说就是调用显卡的一个接口,该对象的GraphicsDevice属性代表当前目标设备的显卡。
示例:
- 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 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);
- //添加横屏和竖屏的支持
- 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 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 should draw itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- // TODO: Add your drawing code here
- spriteBatch.Begin();
- spriteBatch.DrawString(rotationFont, "你现在手机的摆放状态是:" + Window.CurrentOrientation.ToString() + ".", new Vector2(50, 50), Color.White);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1078391
XNA游戏:横竖屏设置相关推荐
- statusBarOrientation设备状态判断--- 横竖屏设置
在一般的视频类APP播放的时候都会支持横屏,这样做的好处就是便于观看.你的项目中支持横屏吗?我们一起了解一下,在iOS9中横竖屏设置的处理方法吧! 简单说明: UIInterfaceOrientati ...
- Android横竖屏设置
默认情况下,当用户手机的"屏幕旋转"选项打开后,旋转手机方向,手机屏幕也会跟随旋转的方向进行横竖屏切换. 设置屏幕旋转的方式有两种: 一.在AndroidManifest.xml设 ...
- iOS开发:App横竖屏设置问题
在iOS开发中,难免会遇到关于手机屏幕是否切换横竖屏的问题,比如一个App整体的界面都需要竖屏显示,那么只用在Xcode里面的General里面的Deployment Info里面把横竖屏选项勾选去掉 ...
- flutter 横竖屏设置
import 'package:flutter/services.dart'; void main(){// 强制横屏SystemChrome.setPreferredOrientations([De ...
- Win7游戏全屏设置
你的系统是win7的吧!改下就行了-- 搜索框输入 regedit 定位到 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsD ...
- Activity 横竖屏切换
前言 在开发中常要处理横竖屏切换,怎么处理先看生命周期 申明 Activity 横竖屏切换时需要回调两个函数 ,所以在此将这个两个函数暂时看成是Activity 横竖屏切换的生命周期的一部分,这两个函 ...
- android虚拟机固定横屏幕竖屏,用VBox虚拟机安装Android 屏幕90度翻转竖屏设置
在虚拟机中安装好Android之后,有一些Android应用(比如UC浏览器.UC桌面)不能安装.但更有一些程序是可以安装,却自动顺时间旋转了90度,操作和看起来非常不爽! 这个情况下,在Androi ...
- 移动端判断手机横竖屏状态
禁用用户自动缩放功能: <meta name="viewport" content="width=device-width, initial-scale=1.0, ...
- android 横竖屏幕切换,Android 横竖屏切换总结
一.Android切换横竖屏 应用的横竖屏设置 应用的横竖屏设置主要是通过Activity的screenOrientation属性控制,属性值如下: 主要有以下两种方式设置screenOrientat ...
最新文章
- 设计模式之状态模块加观察者模式
- 数字万用表测量二极管、三极管
- C++求tree树的高度(附完整源码)
- 使用Spring提供Quartz来实现定时任务
- java学习(40):成员实例的定义和访问
- erp系统是什么东西
- python plot方法的使用_Python bokeh.plotting.figure.step()用法及代码示例
- Aaron Swartz Rewriting Reddit中关于web.py的创建思路
- 【POJ3608】Bridge Across Islands(旋转卡壳求两凸多边形的最短间距)
- chrome扩展程序_如何在20分钟内创建和发布Chrome扩展程序
- 一文读懂电感器的原理、结构、作用及分类
- 闲聊历史上的配角之赵高
- 入职阿里巴巴,阿里P7高级架构师需要哪些技术栈?
- 【读书随记】周末充电,学习Java更轻松(文末送书)
- 美国计算机视觉专业排名,你了解美国计算机视觉专业吗
- postman上一接口返回值作为下一接口传参
- 云周刊】第177期:马云见证!蚂蚁金服推出全球首个区块链跨境汇款服务
- Java实现第九届蓝桥杯缩位求和
- 异步复位同步释放 打两拍
- 大数定理的MATLAB编程,用MATLAB模拟大数定律和中心极限定理.pdf
热门文章
- 堆排序-排序-数据结构和算法
- CF400D Dima and Bacteria(并查集+Floyd)
- python之torchlight使用_Unity3D加载火炬之光资源
- 徐志摩的《再别康桥》
- 频繁默认网关不可用_win10系统默认网关不可用频繁掉线的具体方法
- AnalyticDB向量化引擎
- 银河麒麟Kylin_s10_sp2安装Oracle11g(FS)(亲测有效)
- 2年时间,涨薪20k,想拿高薪还真不能老老实实的工作...
- 广州企业品牌网站建设和网站改版的大趋势
- 【信息安全第三章同余习题】把剩余类1(mod 5)写成模15的剩余类之和