How to slow down or stop key presses in XNA

后端 未结 12 2406
北恋
北恋 2021-02-01 05:38

I\'ve begun writing a game using XNA Framework and have hit some simple problem I do not know how to solve correctly.

I\'m displaying a menu using Texture2D and using th

12条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 05:59

    Ranieri, what does that look like? I am having a hard time juggling these update cycles...

    Hrmmm...

    public static bool CheckKeyPress(Keys key)
    {
        return keyboardState.IsKeyUp(key) && lastKeyboardState.IsKeyDown(key);
    }
    

    SetStates() is private and it is called in the Update()

    private static void SetStates()
    {
        lastKeyboardState = keyboardState;
    
        keyboardState = Keyboard.GetState();
    }
    

    Here is the update...

    public sealed override void Update(GameTime gameTime)
    {
        // Called to set the states of the input devices
        SetStates();
        base.Update(gameTime);
    }
    

    I've tried adding extra checks..

    if (Xin.CheckKeyPress(Keys.Enter) ||
        Xin.CheckButtonPress(Buttons.A))
    {
        if (Xin.LastKeyboardState != Xin.KeyboardState ||
            Xin.LastGamePadState(PlayerIndex.One) != Xin.GamePadState(PlayerIndex.One))
        {
    

    doesn't seem to have any noticeable effects - I can't seem to slow down the menu confirmations,

提交回复
热议问题