//----------------------------------------------------------------------------- // Game.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Net; namespace NetworkStateManagement { /// /// Sample showing how to manage the different game states involved in /// implementing a networked game, with menus for creating, searching, /// and joining sessions, a lobby screen, and the game itself. This main /// game class is extremely simple: all the interesting stuff happens /// in the ScreenManager component. /// public class NetworkStateManagementGame : Game { GraphicsDeviceManager graphicsDeviceManager; ScreenManager screenManager; public ScreenManager ScreenManager { get => screenManager; set => screenManager = value; } // By preloading any assets used by UI rendering, we avoid framerate glitches // when they suddenly need to be loaded in the middle of a menu transition. static readonly string[] preloadAssets = { "gradient", "cat", "chat_ready", "chat_able", "chat_talking", "chat_mute", }; /// /// The main game constructor. /// public NetworkStateManagementGame() { Content.RootDirectory = "Content"; graphicsDeviceManager = new GraphicsDeviceManager(this); graphicsDeviceManager.PreferredBackBufferWidth = ScreenManager.BASE_BUFFER_WIDTH; graphicsDeviceManager.PreferredBackBufferHeight = ScreenManager.BASE_BUFFER_HEIGHT; if (UIUtility.IsMobile) { graphicsDeviceManager.IsFullScreen = true; IsMouseVisible = false; } else if (UIUtility.IsDesktop) { graphicsDeviceManager.IsFullScreen = false; IsMouseVisible = true; } else { throw new PlatformNotSupportedException(); } // Create components. screenManager = new ScreenManager(this); Components.Add(screenManager); Components.Add(new MessageDisplayComponent(this)); Components.Add(new GamerServicesComponent(this)); // Activate the first screens. screenManager.AddScreen(new BackgroundScreen(), null); screenManager.AddScreen(new MainMenuScreen(), null); // Listen for invite notification events. NetworkSession.InviteAccepted += (sender, e) => NetworkSessionComponent.InviteAccepted(screenManager, e); // To test the trial mode behavior while developing your game, // uncomment this line: // Guide.SimulateTrialMode = true; } /// /// Loads graphics content. /// protected override void LoadContent() { foreach (string asset in preloadAssets) { Content.Load(asset); } } /// /// This is called when the game should draw itself. /// protected override void Draw(GameTime gameTime) { graphicsDeviceManager.GraphicsDevice.Clear(Color.Black); // The real drawing happens inside the screen manager component. base.Draw(gameTime); } } }