每次抽奖都重绘不变的背景? [英] Redraw unchanging background on every Draw?

查看:33
本文介绍了每次抽奖都重绘不变的背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单的问题,但我搜索并没有找到其他方法.每次 Draw 都重新绘制背景是没有意义的.有没有办法画一些东西然后把它们留在屏幕上?

This might be a very simple question, but I searched and found no other way to do it. It doesn't make sense to redraw the background on every Draw. Is there a way to draw some things and leave them on the screen?

我试图注释掉

GraphicsDevice.Clear(Color.CornflowerBlue);

但这无济于事.(它的目的是什么?)

But that doesn't help. (What is its purpose?)

推荐答案

您所看到的深紫色被 XNA 和 DirectX 用于指示未初始化的缓冲区.XNA 还将清除缓冲区到这种颜色以模拟 Xbox 360 或 Windows Phone 的行为,因此如果您在 Windows 上构建游戏,它可以"在其他平台上正常工作"(或者更确切地说,因此它在相同的平台上失败)方式,所以你可以调试它).

The dark purple colour you are seeing is used by XNA and DirectX to indicate an uninitialised buffer. XNA will also clear buffers to this colour to emulate the behaviour of the Xbox 360 or Windows Phone, so that if you build a game on Windows, it "just works" on those other platforms (or, rather, so it fails in the same way, so you can debug it).

XNA 是双缓冲的.您不会直接绘制到屏幕上,而是绘制到后台缓冲区".屏幕只显示前缓冲区".每次 GraphicsDevice.Present 被调用(GameEndDraw 中为你调用它),这两个缓冲区被交换,你正在绘制的内容得到显示出来(你会得到一个新的缓冲区来绘制).

XNA is double-buffered. You don't draw directly to the screen, but to a "backbuffer". The screen only displays the "front buffer". Every time GraphicsDevice.Present gets called (Game calls it for you in EndDraw), those two buffers get swapped, and what you were drawing gets displayed (and you get a fresh buffer to draw on).

我不确定为什么 XNA 在交换缓冲区时将其标记为未初始化.我以前从未遇到过这种行为 - 主要是因为想要交换缓冲区保留它们的内容是非常不寻常的.

I'm not sure why XNA marks the buffer as uninitialised when it gets swapped. I haven't come across this behaviour before - mostly because it's very unusual to want to swap buffers and preserve their contents.

通常你想要做的是调用 Game.SupressDraw,当你知道你不会修改屏幕的内容(保存两个调用Draw 和交换).另请参阅此处此处的答案.

Usually what you want to do is call Game.SupressDraw, when you know you're not going to modify the contents of the screen (saving both a call to Draw and a swap). See also answers here and here.

请记住,使用 GraphicsDevice.Clear 清除屏幕非常.而且 XNA 没有背景"或前景"的概念(您总是在缓冲区中已有的任何内容之上绘图).

Keep in mind that clearing the screen with GraphicsDevice.Clear is extremely fast. And that XNA has no concept of "background" or "foreground" (you're always drawing on top of whatever is already in the buffer).

如果您确实有一些需要在帧之间重复使用的渲染成本高的内容,通常您会将其绘制到渲染目标一次,然后每帧将其绘制到屏幕上.但是,一如既往,避免过早优化!显卡专为每帧重绘场景而设计 - 它们非常快!

If you do have some expensive-to-render content that you want to re-use between frames, generally you would draw it into to a render target once, and then draw that to the screen each frame. But, as always, avoid premature optimisation! Graphics cards are designed specifically to redraw scenes every frame - they're pretty damn fast!

这篇关于每次抽奖都重绘不变的背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆