当上重绘屏幕手动控制 [英] Manual control over when to redraw the screen
问题描述
我试图做出XNA回合制roguelike引擎的事情。我基本上比从以前的工作我没有使用名为libtcod基于SDL-roguelike库的移植游戏。我怎样才能修改基本XNA模板的东西,使游戏的不的重绘屏幕每帧,但是,相反,当我想要什么?
I'm trying to make a turn-based roguelike engine thing for XNA. I'm basically porting the game over from a previous work I did using an SDL-based roguelike library called libtcod. How can I modify the basic XNA template thing to make the game not redraw the screen every frame, but, instead, when I want?
推荐答案
这样做的正确的方法是调用 GraphicsDevice.Present()
每当你想绘制后台缓冲到屏幕上。
The correct method for doing this is to call GraphicsDevice.Present()
whenever you want to draw the back buffer onto the screen.
现在这里的困难是游戏
类会自动调用礼物给你(特别是在 Game.EndDraw
),这是你不希望它做的事。幸运的是游戏
提供了一些方法,以防止目前被称为:
Now the difficulty here is that the Game
class automatically calls Present for you (specifically in Game.EndDraw
), which is something you don't want it to do. Fortunately Game
provides a number of ways to prevent Present from being called:
最好的办法是重写 BeginDraw
并使其返回false,以防止一帧被吸入(包括防止绘图
和 EndDraw
被调用),像这样:
The best way would be to override BeginDraw
and have it return false, to prevent a frame from being drawn (including preventing Draw
and EndDraw
from being called), like so:
protected override bool BeginDraw()
{
if(readyToDraw)
return base.BeginDraw();
else
return false;
}
其他的替代品来调用的 Game.SuppressDraw
,或覆盖 EndDraw
这样,它不叫 base.EndDraw()
,直到你准备要在屏幕上显示一个框架。
The other alternatives are to call Game.SuppressDraw
, or to override EndDraw
such that it does not call base.EndDraw()
until you are ready to have a frame displayed on screen.
我个人简单地画每一帧。
Personally I would simply draw every frame.
这篇关于当上重绘屏幕手动控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!