XNA 如何在调整大小时渲染和更新 [英] XNA How to Render and Update while resizing

查看:64
本文介绍了XNA 如何在调整大小时渲染和更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在调整窗口大小的同时继续渲染和更新以使其不会拉伸?

Is it even possible to continue rendering and updating while resizing the window so that it doesn't stretch?

推荐答案

这深深地融入了 XNA 的 Game 类的行为中.我现在正在处理这个确切的问题,但我还没有一个好的解决方案. 我现在如何找到一个解决方案 - 但它没有回答关于缩放的问题 - 所以我已将其发布为问题/答案对.

This is pretty deeply baked into XNA's Game class's behaviour. I'm dealing with this exact problem now, but I don't have a good solution yet. I how now found a solution - but it doesn't answer the bit about scaling - so I've posted it as a question/answer pair over here.

您可以深入思考并断开在开始调整大小时暂停游戏计时器的事件(并在停止时取消暂停).我还没有尝试过这个,我有点不愿意在不理解它们首先存在的原因的情况下这样做.

You could possibly dive in with reflection and disconnect the events that pause the game's timer when you start resizing (and unpause it when you stop). I haven't tried this yet, I'm a bit loathe to do it without understanding why they exist in the first place.

(就我个人而言,我也在考虑让我的游戏订阅调整大小的开始/结束事件,然后在适当的计时器上自己更新,直到 XNA 回来.我不打算这样做担心显示的缩放.)

(Personally I am thinking of having my game subscribe to the resize start/end events as well, and then pumping Update myself on an appropriate timer until XNA comes back. I wasn't going to worry about the scaling of the display.)

解决此问题的一种方法是完全替换 Game 类.XNA WinForms Sample 提供了合适的替代品 - 尽管您必须实现自己的绘制/更新循环和计时.我刚刚在一个旧的关卡编辑器中测试了这个,它在调整大小时可以正常工作.

One way to work around this problem is to replace the Game class entirely. The XNA WinForms Sample provides a suitable replacement - although you have to implement your own Draw/Update loop and timing. I've just tested this in an old level editor and it works just as you want when resized.

尽管当您将窗口变大时它确实会减慢很多,因为它会不断重新分配后台缓冲区以使其变大.您可以替换该行为以使其过度分配后台缓冲区大小,因此不会经常重新分配.

Although it does slow down quite a bit when you make the window larger, as it constantly re-allocates the backbuffer to make it bigger. You could replace that behaviour to make it over-allocate the backbuffer size, so it doesn't reallocate so often.

底层问题与win32有关,在这个GameDev.net 上的线程.但它也没有真正提供令人满意的解决方案.

The underlying problem has something to do with win32, and is described in some detail in this thread on GameDev.net. But it doesn't really provide a satisfying solution either.

注意到 WinForms 示例利用其 OnPaint 方法(并且您通过不断调用 Invalidate 获得一个循环)可能会很有趣.而 XNA 的内置 Game 类订阅了 Application.Idle.

It might be interesting to note that the WinForms sample draws on its OnPaint method (and you get a loop by constantly calling Invalidate). Whereas XNA's built-in Game class subscribes to Application.Idle.

这篇关于XNA 如何在调整大小时渲染和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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