protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // pull in textures. dotTexture = CreateTextureDot(GraphicsDevice); Asset.LoadFrom_Content(Content); Asset.font_MgGenFont.DefaultCharacter = '?'; frameRate = new MgFrameRate(); frameRate.LoadSetUp(this, graphics, spriteBatch, true, false, 60, true); // initialize text input and key command input. // this class process multiple key combinations up to 3. KeysAndTextInput.Initialize(); // example, this is done once. KeysAndTextInput.AddMethodsToRaiseOnKeyBoardActivity(OnTextInput, OnKeyCommandsInput, this); // disable or enable like so prevents garbage collections from occuring. KeysAndTextInput.EnableKeyCommandsInput(this); KeysAndTextInput.EnableTextInput(this); // to visually test and see the above class in practical use. // don't have to save the refernce this is a static instance. new VisualKeyboardDisplay(); // record characters. VisualKeyboardDisplay.RecordTypedCharacters = true; VisualKeyboardDisplay.DisplayRecordedTypedCharacters = true; VisualKeyboardDisplay.DisplayKeypressText = true; }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // Updates and process key related actions. KeysAndTextInput.Update(gameTime); // Update the frame rate and gc display. frameRate.Update(gameTime); int tmp = msg2.Length; msg2.Clear(); msg2 .Append("\n F12 to force a collect. , Control + Delete to clear the string. NumLock Fixed or not fixed fps.").Append("") .Append("\n F7 F8 DisplayRecordedTypedCharacters ").Append(VisualKeyboardDisplay.DisplayRecordedTypedCharacters) .Append("\n msg2.Length ").Append(tmp).Append(" msg2.Capacity ").Append(msg2.Capacity) .Append("\n msg.Length ").Append(msg.Length).Append(" msg.Capacity ").Append(msg.Capacity) .Append("\n RepressSpeed ").Append(KeysAndTextInput.RepressSpeed) .Append("\n RepeatKeyAccelerationRatio ").Append(KeysAndTextInput.RepeatKeyAccelerationRatio) .Append("\n RepeatKeyMaxAccelerationRatio ").Append(KeysAndTextInput.RepeatKeyMaxAccelerationRatio) ; //if (Keyboard.GetState().IsKeyDown(Keys.F12)) // frameRate.ClearCollectionTrackingAndGcCollect(); // display recorded characters. if (Keyboard.GetState().IsKeyDown(Keys.F7)) { VisualKeyboardDisplay.DisplayRecordedTypedCharacters = true; // so it looks like spritebatch is the culprit here must be a buffer array resize kinda makes sense. } // hide recorded characters. if (Keyboard.GetState().IsKeyDown(Keys.F8)) { VisualKeyboardDisplay.DisplayRecordedTypedCharacters = false; } if (Keyboard.GetState().NumLock) { this.IsFixedTimeStep = true; } else { this.IsFixedTimeStep = false; } base.Update(gameTime); }