手动控制何时重绘屏幕

发布于 2024-09-29 18:55:58 字数 143 浏览 3 评论 0原文

我正在尝试为 XNA 制作一款回合制 Roguelike 引擎。我基本上是从我之前使用基于 SDL 的 Roguelike 库(称为 libtcod)所做的工作移植游戏的。我怎样才能修改基本的 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独患者 2024-10-06 18:55:58

执行此操作的正确方法是每当您想要将后台缓冲区绘制到屏幕上时调用GraphicsDevice.Present()

现在这里的困难是 Game 类自动为您调用 Present(特别是在 Game.EndDraw 中),这是您不希望它执行的操作。幸运的是 Game 提供了多种方法来防止调用 Present:

最好的方法是重写 BeginDraw 并让它返回 false,以防止绘制框架(包括阻止调用 DrawEndDraw),如下所示:

protected override bool BeginDraw()
{
    if(readyToDraw)
        return base.BeginDraw();
    else
        return false;
}

其他替代方法是调用 Game.SuppressDraw,或重写 EndDraw 以便在您准备好在屏幕上显示框架之前,它不会调用 base.EndDraw()

就我个人而言,我会简单地绘制每一帧。

The correct method for doing this is to call GraphicsDevice.Present() whenever you want to draw the back buffer onto the screen.

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:

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;
}

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.

无可置疑 2024-10-06 18:55:58

您不需要从 Game 类继承,它完全是可选的。您可以编写自己的类,仅在需要时重绘屏幕。不过,该类中有一些有用的代码,因此您可以使用 Reflector 从那里复制代码,然后更改其逻辑。

You don't need to inherit from Game class, it is entirely optional. You can write your own class which redraws the screen only when you want. There's some useful code in the class though, so you can use Reflector to copy code from there and then change its logic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文