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