惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - tiny羊

自制一个可以为XNA所用的GIF 转 PNG 的小工具 展示PNG动画精灵 C#关键字 之 访问与上下文 C#关键字 之 转换 C#关键字 之 运算符 C#关键字 之 参数 - tiny羊 C#关键字 之 块 C#关键字 之 修饰符 Sql小题几道 泛型类及系统中常用的泛型类 泛型函数 Javascript简明教程6 定义时执行与单例模式 编程语言发展趋势图 Javascript简明教程系列 Javascript简明教程五 DOM Javascript简明教程四 作用域 Javascript简明教程三 函数 Javascript简明教程二 变量 - tiny羊 Javascript简明教程一 使用Javascript
XNA 4.0中实现简单的快捷键模板
tiny羊 · 2011-12-27 · via 博客园 - tiny羊

在XNA中,可以通过GraphicsDeviceManager提供的ToggleFullScreen来进行全屏状态转换

通常的游戏中,都会使用Alt+Enter来进行全屏状态切换,所以我们可以在Update中使用如下代码进行全屏切换

   1: protected override void Update(GameTime gameTime)
   2:  
   3: {
   4:  
   5: if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
   6:  
   7: this.Exit();
   8:  
   9: if (Keyboard.GetState()[Keys.RightAlt] == KeyState.Down &&
  10:  
  11: Keyboard.GetState()[Keys.Enter] == KeyState.Down)
  12:  
  13: {
  14:  
  15: graphics.ToggleFullScreen();
  16:  
  17: }
  18:  
  19: base.Update(gameTime);
  20:  
  21: }
  22:  

在里我们使用Keyboard.GetState来获取按键状态

当然我们可以封装起方法来进行操作

   1: protected override void Update(GameTime gameTime)
   2:  
   3: {
   4:  
   5: if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
   6:  
   7: this.Exit();
   8:  
   9: KeyboardTemplate(() => graphics.ToggleFullScreen(), Keys.Enter, Keys.RightAlt);
  10:  
  11: base.Update(gameTime);
  12:  
  13: }
  14:  
  15: void KeyboardTemplate(Action action, params Keys[] keys)
  16:  
  17: {
  18:  
  19: if (keys.Any(key => Keyboard.GetState()[key] != KeyState.Down))
  20:  
  21: {
  22:  
  23: return;
  24:  
  25: }
  26:  
  27: action();
  28:  
  29: }
  30:  

当然我们也可以添加其它一些功能

   1: protected override void Update(GameTime gameTime)
   2:  
   3: {
   4:  
   5: if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
   6:  
   7: this.Exit();
   8:  
   9: KeyboardTemplate(graphics.ToggleFullScreen, Keys.Enter, Keys.RightAlt);
  10:  
  11: KeyboardTemplate(this.Exit, Keys.F4, Keys.LeftControl);
  12:  
  13: base.Update(gameTime);
  14:  
  15: }

这样就可以在Ctrl+F4的时候关闭当前游戏了