Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm playing with XNA 4.0, VS2010. I've created a window (not maximized) and drawn some sprites. All is good until I resize the window, after which the sprites stop displaying or only partially display. I'm pretty sure it has something to do with needing to reset the device or something, but can't find any clear instructions or sample code. It's not just a case of needing to increase the preferredbackbuffer size, because even if I shrink the window I get this symptom. I've looked at the source code that I was able to get from Microsoft before they shut down XNA, but it doesn't actually explain anything.

Any help or advice?

If it makes any difference I'm creating DrawableGameComponents and doing my updates and drawing in their Draw/Update routines.

share|improve this question
    
So, while reading random topics I came upon a comment to the effect that a device reset clears rendertargets. Eek! Does it clear textures as well? Does this essentially mean that I have to rebuild all my sprites from the original PNGs every time the window is resized? –  Donutz May 2 '13 at 16:33
    
If you're into XNA, I suggest you try MonoGame. It's open-source, and pretty decent. –  ashes999 Jul 2 '13 at 22:43
add comment

2 Answers

So, after some research, I found the problem (Jamie Hyneman: Well, THERE'S your problem!). Essentially the comment I referenced earlier describes the issue. When you change window size, the device is lost. When the device is lost, rendertargets are invalidated (but not textures). You can either check the RenderTarget2D.IsContentLost flag, or attach to the RenderTarget2D.ContentLost event to trap this as it happens.

Also, the Rendertargets don't seem to ALWAYS get invalidated. It may depend on resource usage.

share|improve this answer
add comment

When you change the size of the xna control... the viewport is changed...

so you have to recreate your camera projection matrix..

if you are using spritebatch you should recreate it to initialize the projection matrix that it uses internally.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.