I have my application set to use the full screen. If I hit alt tab, go into another app, then alt+tab back into my game, it's solid gray, and then locks up. I wrote some simple code to check the keyboard state, and close the app if I hit escape, but that doesn't even work.
I just assumed that this would all be handled for me, out of the box... Do I have to write anything myself to fix this

Minimizing and Maximizing
abc_acb
Vincent Fournier
Yeah for XNA 1.0!
BruceS
kcchesnut
First you need to uninstall the beta version, install the 1.0 version. Then change your code to load the textures using the content manager. Make sure you're calling LoadResources from the LoadGraphicsContent method:
protected override void LoadGraphicsContent(bool loadAllContent)
{
base.LoadGraphicsContent(loadAllContent);
if (loadAllContent)
{
contentManager = new ContentManager(Services);
LoadResources();
}
}
Get rid of the BeginScene and EndScene and Present lines in the Draw method, they're no longer applicable. After that we'll see what happens.
Ke Sun
Jehan Badshah
I've been out of the game/graphics programming scene for a while.
Josh Smith
When I try opening the sln in the new version, I get an error telling me that the project was saved in an incompatible version of XNA game studio express. Weird... Anyway...
Here's my code.
void LoadResources()
{
// load textures
textures[0] = Texture2D.FromFile(graphics.GraphicsDevice, "green.png");
textures[1] = Texture2D.FromFile(graphics.GraphicsDevice, "red.png");
textures[2] = Texture2D.FromFile(graphics.GraphicsDevice, "blue.png");
textures[3] = Texture2D.FromFile(graphics.GraphicsDevice, "purple.png");
textures[4] = Texture2D.FromFile(graphics.GraphicsDevice, "red.png");
spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
}
protected override void Draw()
{
// Make sure we have a valid device
if (!graphics.EnsureDevice())
return;
graphics.GraphicsDevice.Clear(Color.Black);
graphics.GraphicsDevice.BeginScene();
// start the spriteBatch
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
Vector2 o;
o.X = 512;
o.Y = 440;
spriteBatch.Draw(textures[0], new Rectangle((int)o.X + 60, (int)o.Y , piece.Width, piece.Height), Color.White);
spriteBatch.Draw(textures[1], new Rectangle((int)o.X + 30 , (int)o.Y - 52 , piece.Width, piece.Height), Color.White);
spriteBatch.Draw(textures[2], new Rectangle((int)o.X - 30, (int)o.Y - 52, piece.Width, piece.Height), Color.White);
spriteBatch.Draw(textures[3], new Rectangle((int)o.X - 60, (int)o.Y, piece.Width, piece.Height), Color.White);
spriteBatch.Draw(textures[4], new Rectangle((int)o.X - 30, (int)o.Y + 52, piece.Width, piece.Height), Color.White);
spriteBatch.Draw(textures[1], new Rectangle((int)o.X + 30, (int)o.Y + 52, piece.Width, piece.Height), Color.White);
spriteBatch.End();
// Let the GameComponents draw
DrawComponents();
graphics.GraphicsDevice.EndScene();
// presents the contents of the next buffer
graphics.GraphicsDevice.Present();
}
rwbogosian
DiamondDavo
I have an Menu object in my program that stores references to a RenderTarget2D and a SpriteBatch that are initially created by and stored as members of the Game instance. They are initialized inside the Game's LoadGraphicsContent method, outside of the if(loadAllContent) conditional.
If I minimize the window and then restore it, the RenderTarget2D and SpriteBatch need to be re-initialized. The part I find a bit confusing is that the references inside my Menu object need to be reset. If I don't reset them, I'll get an exception telling me that it "can't access a disposed object". So for a solution, inside the LoadGraphicsCopntent method, after the RenderTarget2D and the SpriteBatch get initialized, I check if the Menu object is null or not. If it isn't, then I pass it references to the reinitialized RenderTarget2D and SpriteBatch and everything works ok.
This seems like a clunky way of doing things. If the Menu object is already storing references to these things, why should I need to pass them again after they get reinitialized Is there a better way to organize this stuff
One other thing I am a little unclear on: in this situation, is it ever necessary to call the Dispose() method on either the RenderTarget2D or the SpriteBatch By the looks of it, they automatically get disposed since I get that exception. When would it actually be necessary to call Dispose() Thanks.
-Aaron
gumtoo
Ok...wait a minute. I just want to get something straight in my head, regarding what you just stated. I am very new to programming in general, and C# + XNA in particular. And what you're talking about sounds like a solution to an issue I was attempting to wrap my noodle around.
If I reload my game's visual resources (primarily textures, what I'm working on now is 2D and sprite-based), is it possible to actually change the graphics that my game is using. In other words, can I change what textures my game is using for its sprites just by calling the LoadGraphicsContent() again I was worried about resolution-switching my game. I like to keep everything as neat and tidy as possible. And the only way to have 100% accuracy for a 2D title is to use separate textures for each possible resolution. So the game would use different sprites for different screen resolutions.
Would it be possible for me to pass an argument into the LoadGraphicsContent() method that would allow me to decide which set of sprites I wanted to load If this were possible, I would be able to change the resolution that my game was running at anytime the player wanted to, and I wouldn't have to worry about my sprites degrading due to up or downscaling.
Looooooka
GavH
It works fine for me with no special coding. Are you properly handling the LoadGraphicsContent calls e.g. recreating SpriteBatch and reloading textures when loadAllContent is true, etc.