How to make a XNA window close without shutting down the game - c#

I am making a game that has a main home screen (that is a windows form) and i need some code that will just close the xna window but not the form.
I've looked everywhere but can't seem to find an answer. I figured out how to open the form, I just need to close the opened xna window so just my main menu is there and i can start another xna game.

There is an answer to your question here. Essentially, you will need to modify the opacity to hide the game window. The game will still be active.
Edit
my game continues to run in the backgound and so on my main menu i can't start another instance of that game
If you need to completely close the XNA game, the game will need to be launched from the Windows Form application. In your Windows Form application you can use:
Game1 myGame = new Game1();
myGame.Run();
to run the XNA game. Then when you use Game.Exit() (in the XNA application) to close the game, the main menu should still be open in the background.

Related

The game window freezes when calling Application.Quit()

I have put together a small project for WebGL, there is an exit button,(Application.Quit()), but when it is called, the window just freezes.
public void ExitGame()
{
print("exitGame");
Application.Quit();
}
The Application.Quit() method is a great way to quit the game on a desktop game but it can't be use to close a browser tab for example in your case, where you are working with WebGL.
What you could instead try is to redirect the player to a new webpage when the player eventually quits the game.
Quitting is used in desktop apps, and isn't designed for use in WebGL builds. Quitting from a WebGL game isn't possible - you can't close the window.

How to open any specific scene when the game opens

My question is that, how can I set any scene in unity as first scene (means it will open first when the game starts).
As I started making my game in unity, instead of making main menu I made LEVEL 1, and as a result when the game opens it directly starts the game by showing level 1.
So how can I set my main menu as the first scene
To further upon Retired Ninja's comment, to set a specific default scene when the game opens, you need to set the ordering of the scenes so that the one you want to start with is first, see the picture below:
The main menu screen comes first in the list of scenes, this means it will run on startup.
More details here where it has been answered on the Unity Forums:
https://answers.unity.com/questions/44953/set-first-scene.html

Change the Opening Window in Visual Studio

I am making an application, but silly me I made the main application in the Main Window, but I need to make an opening screen with a start button which opens the main application, any help?

Window emitting a sound when I try to restore it from the taskbar

I'm working on a rather big project with my team and after a while, we struck into a big problem.
Infact when we minimize the main window of the application, clicking on the taskbar to restore it results in a "bing" sound (the one that windows uses when you are trying to interact with a background window when a modal dialog is opened on it). I can't restore the window except if I press ENTER button (after obviusly clicking on it).
We are using XNA to render something inside a WindowsFormsHost component in our WPF application and the problem comes out when we change something that is not connected directly with wpf (something inside the rendering engine, so it works only with XNA).
I can't post any code because I don't own any rights of it and would be meaningless because the project is enough big.
So my question is: what are the things that can produce a problem like this one (unable to restore window sound) when you click on the taskbar?
At least I can understand where to search for this bug, because I don't even understand where I shall dirt my hands in.
Important notes: I'm using a splash screen and the problems come up when I do something on a second window (so not directly the main one) which is not modal
Thanks for any suggestion
We solved the problem by finding out that there is a bug with an external component that we used inside our application. Still I don't understand how this bug has been created, if someone has a better answer I'll mark it.

Question about an application not getting focus in XP/W2K3

I have an application written in .NET. The previous version had no problems: you double-click on the icon or run it from a command line and when it starts up, it's the main window and has focus as you'd expect.
The latest version displays a splash screen before the main window and now the splash screen comes to the foreground ok but the main one does not always end up the main window. Sometimes it does, sometimes it doesn't. (When launched from the command line it invariably doesn't). When the main window does not come to the foreground and get focus, the taskbar icon shows as a steady orange.
I see lots of hits on the net about how MS added a facility to prevent applications stealing focus from others, centered around the ForegroundLockTimeout registry setting and related settings, but the behaviors described above for the different versions happen on the same machine.
I have tried called Activate in the main form when it finally gets created, and also SetForegroundWindow, all to no avail.
Any help is appreciated.
You should probably have the splash screen set focus to the main app window as it is going away.
As far as Window's knows your splash screen IS your app since it's the first toplevel window shown after the process is started. So that window gets the focus, but any OTHER window trying to grab focus on that same app startup (the icon click/run command) is believed to be a focus thief.
You can get around this by having the window that Window's believes has a right to have focus be the one to transfer focus to a new window.
So you splash should SetFocus on the main window BEFORE the splash is destroyed. If you destroy the focus window, then the focus is nowhere, which is probably what is happening currently in your app.
Sounds like your main window doesn't always get the focus back from the splash screen. Have you tried simply calling SetFocus in the main form's OnLoad handler?MSDN
I just corrected a similar problem. Just make sure your splash screen closes after your main form as shown (it will show in background of the splash if your splash is "always on top").

Categories