/// <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. debugFont = Content.Load <SpriteFont>("Fonts/debug"); // Launch the first screen. currentScreen = new ScreenElements.SettingsScreen(this, null); currentScreen = new ScreenElements.WorldViewScreen(this, null); }
/// <summary> /// Constructor with default state setup /// </summary> public InteractiveScreenElement(ScreenElement previousScreenElement, GraphicsDevice graphicsDevice, PlayerIndex playerIndex = PlayerIndex.One) : base(previousScreenElement, graphicsDevice) { activePlayer = playerIndex; inputState = new InputState(); //kbDispatcher = new KeyboardDispatcher(window); console = new GUI.ConsoleManager(); // Set default last states for first frame inputState.lastKeyboardState = Keyboard.GetState(); inputState.lastMouseState = Mouse.GetState(); inputState.lastGamePadState = GamePad.GetState(activePlayer); }
/// <summary> /// Creates the ScreenElement /// </summary> public DrawableScreenElement(ScreenElement previousScreenElement, GraphicsDevice graphicsDevice) : base(previousScreenElement) { // Add graphics systems this.graphicsDevice = graphicsDevice; this.viewport = graphicsDevice.Viewport; // Create a SpriteBatch and ModelBatch spriteBatch = new SpriteBatch(graphicsDevice); modelBatch = new ModelBatch(graphicsDevice); // Create resource managers voxelContent = new VoxelMeshManager(graphicsDevice); // Handle device reset graphicsDevice.DeviceReset += OnDeviceReset; }
/// <summary> /// All screens must check and update their transition state. /// </summary> private ScreenElement UpdateState(TimeSpan frameStepTime) { // Should only happen upon the first frame. if (screenStatus == ScreenStatus.Waiting) { screenStatus = ScreenStatus.TransitionOn; } if (screenStatus == ScreenStatus.TransitionOn) { // The screen should transition on and become active. if (transition.Updating(frameStepTime, transition.onTime, -1)) { // Still busy transitioning. screenStatus = ScreenStatus.TransitionOn; } else { // Transition finished. screenStatus = ScreenStatus.Active; } } if (screenStatus == ScreenStatus.TransitionOff) { // Exiting screens should transition off. if (!transition.Updating(frameStepTime, transition.offTime, 1)) { // When the transition finishes, unload and return to the previous screen UnloadContent(); return(previous); } } // If a next screen is loaded, unload this screen and return it if (nextScreen != null) { ScreenElement screen = nextScreen; nextScreen = null; return(screen); } return(this); }
/// <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) { // Start drawing the ScreenElements base.Draw(gameTime); // Draw the current screen currentScreen.Draw(gameTime.ElapsedGameTime); SpriteBatch.Begin(); debugString.Append("Elapsed update time: ").Concat(stopWatch.ElapsedMilliseconds, 0); SpriteBatch.DrawString(debugFont, debugString, new Vector2(GraphicsDevice.Viewport.Width - 160f, 0), Color.White); debugString.Clear(); SpriteBatch.End(); // Swap screen for the next frame if (nextScreen != currentScreen) { currentScreen = nextScreen; } stopWatch.Stop(); }
/// <summary> /// Constructor with default transition /// </summary> public ScreenElement(ScreenElement previousScreenElement) { previous = previousScreenElement; transition = new ScreenTransition(TimeSpan.Zero); children = new List <ScreenElement>(); }