Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I run a console application before running my game?
    primarykey
    data
    text
    <p>What I want to do is run a console application, have the user input some details, then pass the user input to my game.</p> <p>I want the user to specify the resolution of the game, to be put into PreferredBackBuffer.</p> <p>Is this possible? I know I can write a settings file and read from that, but I'd rather just cut that part out and do it directly.</p> <p>Here is the "game" I have. I left out Player.cs as I don't think it's imperative to show for the sake of my question.</p> <p>Main.cs</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace SimplePlayer { public class Main : Microsoft.Xna.Framework.Game { const string fileName = "AppSettings.dat"; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D spaceTexture; Player playerShip; public Main() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; ReadRes(); } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); spaceTexture = Content.Load&lt;Texture2D&gt;("spaceBackground"); Texture2D playerTexture = Content.Load&lt;Texture2D&gt;("shipSprite"); playerShip = new Player(GraphicsDevice, new Vector2(400, 300), playerTexture); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); playerShip.Update(gameTime); UpdateInput(); base.Update(gameTime); } private void UpdateInput() { KeyboardState keyState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); if (keyState.IsKeyDown(Keys.Up) || gamePadState.DPad.Up == ButtonState.Pressed) { playerShip.Accelerate(); } if (keyState.IsKeyDown(Keys.Down) || gamePadState.DPad.Down == ButtonState.Pressed) { playerShip.MoveReverse(); } if (keyState.IsKeyDown(Keys.Left) || gamePadState.DPad.Left == ButtonState.Pressed) { playerShip.StrafeLeft(); } if (keyState.IsKeyDown(Keys.Right) || gamePadState.DPad.Right == ButtonState.Pressed) { playerShip.StrafeRight(); } } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(spaceTexture, Vector2.Zero, Color.White); playerShip.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); } public void SetWindowSize(int x, int y) { graphics.PreferredBackBufferWidth = x; graphics.PreferredBackBufferHeight = y; graphics.ApplyChanges(); } } } </code></pre> <p>Program.cs</p> <pre><code>using System; namespace SimplePlayer { #if WINDOWS static class Program { static void Main(string[] args) { using (Main game = new Main()) { game.Run(); } } } #endif } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload