When I resize the game window and the viewport's height becomes 0, GC disposes of spritebatch, I think. Is this what happens? How do I prevent this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Form gameForm = (Form)Form.FromHandle(Window.Handle);
gameForm.MinimumSize = new System.Drawing.Size(800, 600);
Short and sweet!
回答2:
I had this same problem and some quick debugging shows that XNA calls UnloadContent and then LoadContent again to reinitialise resources; my guess it it loses the GraphicsDevice or something, hence the reload.
Creating things pertaining to the GraphicsDevice in LoadContent solves this problem.
Now, for this particular case, setting a minimum size is a good idea, but I don't know if this is a portable solution between Xbox and Windows. However, there might be other situations in which something similar occurs, where UnloadContent is called, so it's probably best to adhere to this practice.