示例#1
0
        /// <summary>
        /// Is called every update frame
        /// </summary>
        /// <param name="args">FrameEventArgs mainly keeps track of the time between update frames</param>
        protected override void OnUpdateFrame(FrameEventArgs args)
        {
            // Increment the total elapsed time
            timeElapsed += args.Time;

            // Return if the window isn't focussed
            // If running with break points, disable this, or this will always return
            if (!IsFocused)
            {
                return;
            }

            // Update the InputHandler
            inputHandler.Update(KeyboardState.GetSnapshot(), MouseState.GetSnapshot());

            // Update the Camera
            camera.Update(args.Time);

            // Check if the Escape button is pressed
            if (inputHandler.IsKeyDown(Keys.Escape))
            {
                // Close the window
                Close();
            }

            // Call Globals' update, this updates the active Buttons as well as the AudioManager
            Globals.Update(args.Time);

            base.OnUpdateFrame(args);
        }
示例#2
0
 private void MainWindowUpdateFrame(FrameEventArgs obj)
 {
     // Use seperate locks for update and render to avoid stuttering
     lock (_updateFrameLock)
     {
         var userEvent = new UserInputStateEvent(KeyboardState.GetSnapshot(), MouseState.GetSnapshot(), obj.Time);
         var task      = Task.Run(async() =>
         {
             await EventChannel.Writer.WriteAsync(userEvent, _cancellationTokenManager.Token).AsTask();
         });
         task.Wait(_cancellationTokenManager.Token);
     }
 }