Hello everywone,
I have problem with exiting game window but it freezes like it cannot exit game.
MonoGame.cs from Engine Directory
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace HLMono
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class MonoGame : Game
{
public GraphicsDeviceManager graphics
{
get; set;
}
public SpriteBatch spriteBatch
{
get; set;
}
public MonoGame()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferHeight = 640;
graphics.PreferredBackBufferWidth = 820;
Content.RootDirectory = "Content";
graphics.ApplyChanges();
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
Client.cs from Engine directory
using Microsoft.Xna.Framework;
using System;
namespace HLMono.Engine
{
public class Client
{
public MonoGame jGame
{
get; set;
}
private GraphicsDeviceManager jGraphics
{
get; set;
}
private string jWidth = "";
private string jHeight = "";
public int Host(string[] args)
{
jGame = new MonoGame();
jGame.graphics.IsFullScreen = true;
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "-width" || args[i] == "-w")
{
jWidth = args[i + 1];
jGame.graphics.PreferredBackBufferWidth = int.Parse(jWidth);
}
if (args[i] == "-height" || args[i] == "-h")
{
jHeight = args[i + 1];
jGame.graphics.PreferredBackBufferHeight = int.Parse(jHeight);
}
/**
* -windowed
*/
if (args[i].Equals("-windowed"))
{
jGame.graphics.IsFullScreen = false;
jGame.graphics.ApplyChanges();
}
}
jGame.Exiting += OnExiting;
jGame.Run();
return args.Length;
}
private void OnExiting(object sender, EventArgs args)
{
jGame.graphics.ToggleFullScreen();
jGame.Exit();
}
}
}
And Program.cs
using HLMono.Engine;
using System;
namespace HLMono
{
/// <summary>
/// The main class.
/// </summary>
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
Client _cl = new Client();
_cl.Host(args);
return 0;
}
}
}
Why I need it. because I want create real game with arguments like any games have same arguments
example
game.exe -w 800 -h 600 -windowed = It means windowed version with game or
game.exe -w 1024 -h 768 = It means fullscreen mode with filled monitor
I have problem with exiting of game-window. Why does it force to exit. If I click close Button. It doesn’t happen…
Thanks for help me!