XNA游戏开发之(四)——改变Draw频率

        【原创】Alex

  当运行XNA游戏时,XNA会以尽可能大的频率调用Draw方法

  Draw的频率大于屏幕刷新频率时,Draw设置失效。

  如果屏幕刷新频率只有每秒100次,每秒绘制110次是无用的。在PC和Xbox360平台上,,屏幕刷新率是由PC屏幕和它的设置决定的,Zune 30每秒刷新60次,其他Zune设备每秒刷新30次。

  Update方法每秒调用60次。如果游戏计算量太大,Draw方法调用次数会变少以保证Update方法可以每秒调用60次。

  在某些情况中,以最大频率调用Draw方法是有用的,需要在XNA游戏中使用的最大帧频率时,可以将graphics.SynchronizeWithVerticalRetrace变量设置为true。

     必须在Game的构造函数顶部加入这行代码,因为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.Media;
11 using Microsoft.Xna.Framework.Net;
12 using Microsoft.Xna.Framework.Storage;
13
14 namespace Alex
15 {
16 /// <summary>
17 /// This is the main type for your game
18 /// </summary>
19 public class AlexGame : Microsoft.Xna.Framework.Game
20 {
21 GraphicsDeviceManager graphics;
22 SpriteBatch spriteBatch;
23
24 public AlexGame()
25 {
26 graphics = new GraphicsDeviceManager( this );
27 Content.RootDirectory = " Content " ;
28 // 将Draw刷新频率设置为最大
29 graphics.SynchronizeWithVerticalRetrace = true ;
30 }
31
32 /// <summary>
33 /// Allows the game to perform any initialization it needs to before starting to run.
34 /// This is where it can query for any required services and load any non-graphic
35 /// related content. Calling base.Initialize will enumerate through any components
36 /// and initialize them as well.
37 /// </summary>
38 protected override void Initialize()
39 {
40 // TODO: Add your initialization logic here
41 this .TargetElapsedTime = TimeSpan.FromSeconds( 1.0f / 100.0f );
42 base .Initialize();
43 }
44
45 /// <summary>
46 /// LoadContent will be called once per game and is the place to load
47 /// all of your content.
48 /// </summary>
49 protected override void LoadContent()
50 {
51 // Create a new SpriteBatch, which can be used to draw textures.
52 spriteBatch = new SpriteBatch(GraphicsDevice);
53
54 // TODO: use this.Content to load your game content here
55 }
56
57 /// <summary>
58 /// UnloadContent will be called once per game and is the place to unload
59 /// all content.
60 /// </summary>
61 protected override void UnloadContent()
62 {
63 // TODO: Unload any non ContentManager content here
64 }
65
66 /// <summary>
67 /// Allows the game to run logic such as updating the world,
68 /// checking for collisions, gathering input, and playing audio.
69 /// </summary>
70 /// <param name="gameTime"> Provides a snapshot of timing values. </param>
71 protected override void Update(GameTime gameTime)
72 {
73 // Allows the game to exit
74 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
75 {
76 this .Exit();
77 }
78 if (Keyboard.GetState().IsKeyDown(Keys.Escape))
79 {
80 this .Exit();
81 }
82
83 this .Window.Title = gameTime.IsRunningSlowly.ToString();
84
85 // TODO: Add your update logic here
86
87 base .Update(gameTime);
88 }
89
90 /// <summary>
91 /// This is called when the game should draw itself.
92 /// </summary>
93 /// <param name="gameTime"> Provides a snapshot of timing values. </param>
94 protected override void Draw(GameTime gameTime)
95 {
96 GraphicsDevice.Clear(Color.CornflowerBlue);
97
98 // TODO: Add your drawing code here
99
100 base .Draw(gameTime);
101 }
102 }
103 }
104

 

 

 

Update和Draw方法调用频率的重要性

更新逻辑放置在Update方法中,Update频率的减少会导致游戏中的所有物体变慢。

当Draw调用频率小于屏幕刷新频率时,只有游戏的视觉表现会暂时受影响,游戏帧频率暂时由每秒100帧降到80帧不容易察觉。

如果必要,XNA会降低Draw的频率以保证Update能以每秒60帧的频率调用。

 

 

转载于:https://www.cnblogs.com/AlexCheng/archive/2010/04/26/2120351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
系统根据B/S,即所谓的电脑浏览器/网络服务器方式,运用Java技术性,挑选MySQL作为后台系统。系统主要包含对客服聊天管理、字典表管理、公告信息管理、金融工具管理、金融工具收藏管理、金融工具银行卡管理、借款管理、理财产品管理、理财产品收藏管理、理财产品银行卡管理、理财银行卡信息管理、银行卡管理、存款管理、银行卡记录管理、取款管理、转账管理、用户管理、员工管理等功能模块。 文中重点介绍了银行管理的专业技术发展背景和发展状况,随后遵照软件传统式研发流程,最先挑选适用思维和语言软件开发平台,依据需求分析报告模块和设计数据库结构,再根据系统功能模块的设计制作系统功能模块图、流程表和E-R图。随后设计架构以及编写代码,并实现系统能模块。最终基本完成系统检测和功能测试。结果显示,该系统能够实现所需要的作用,工作状态没有明显缺陷。 系统登录功能是程序必不可少的功能,在登录页面必填的数据有两项,一项就是账号,另一项数据就是密码,当管理员正确填写并提交这二者数据之后,管理员就可以进入系统后台功能操作区。进入银行卡列表,管理员可以进行查看列表、模糊搜索以及相关维护等操作。用户进入系统可以查看公告和模糊搜索公告信息、也可以进行公告维护操作。理财产品管理页面,管理员可以进行查看列表、模糊搜索以及相关维护等操作。产品类型管理页面,此页面提供给管理员的功能有:新增产品类型,修改产品类型,删除产品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值