Is it even possible to continue rendering and updating while resizing the window so that it doesn't stretch?
-
I don't think that's possible, though they may be some tricks to do with system calls and prevent the window from pausing, though I must say, drawing (updating part might be ok) and changing the viewport size while resizing might be slow and unresponsive to the extent it's better not to draw while resizing at all. – user1306322 Feb 25 '13 at 21:22
-
[This question/answer pair](http://gamedev.stackexchange.com/q/51376/288) might be helpful. It tells you how to continue rendering (although it doesn't fix stretching). – Andrew Russell Mar 20 '13 at 03:08
1 Answers
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. EDIT: 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.
(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.)
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.
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.
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
.

- 1
- 1

- 26,924
- 7
- 58
- 104
-
Just because I'm a new to reflection. How exactly do I access this.host.suspend and resume? – Tyler Wiebe Mar 27 '13 at 00:11
-
This should get you started: `var fieldInfo = type.GetField("host", BindingFlags.NonPublic | BindingFlags.Instance); object host = fieldInfo.GetValue(this);`. Where `type` is `this.GetType()` possibly with a few `.BaseType`s tacked on the end. Do it again on `host` for `Suspend` and `Resume` - although I think you might need `GetProperty` instead, here. (I'm afraid I don't have exact code, because I used a modified version of ExposedObject.) – Andrew Russell Mar 27 '13 at 01:22
-
I've managed to find the host easy enough, but the Suspend and Resume have me stumped. I'm positive I've tried every possible combination to find them, but I guess I missed one. Anyway, if can let me know where they're located, it be much appreciated. – Tyler Wiebe Apr 07 '13 at 06:38
-
@TylerWiebe I've added the necessary reflection code to [my Q/A pair on GDSE](http://gamedev.stackexchange.com/a/51377/288). Turns out you need `BaseType` and `GetField`. – Andrew Russell Apr 08 '13 at 06:43
-