XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Input Issues

Last post 25/03/2008 9:39 by Jim Perry. 7 replies.
  • 24/03/2008 3:26

    Input Issues

    When checking keyboard function, I basically want to have the player be able to jump and move at the same time. The first way I tried this was as so:

    void CheckKeys()
    {

    if (keys.IsKeyDown(Keys.Left))
    {
    MoveCharLeft();
    }

    if (keys.IsKeyDown(Keys.Up))
    {
    JumpChar();
    }
    }

    And it didn't update fast enough to do both, so I tried:

    void CheckKeys()
    {
    if (keys.IsKeyDown(Keys.Left) && keys.IsKeyDown(Keys.Up)))
    {
    MoveCharLeft();
    JumpChar();
    }
    }
     
    and when setting the breakpoint on those lines inside the if, it doesn't trigger at all.
     
    Any ideas?
  • 24/03/2008 6:33 In reply to

    Re: Input Issues

    just checking,

    you are calling

    KeyboardState keys = Keyboard.GetState();

    Information is not knowledge, knowledge is not wisdom, wisdom is not truth, truth is not beauty, beauty is not love, love is not music, music is the best! Wisdom is the domain of the Wis (which is extinct).
  • 24/03/2008 13:22 In reply to

    Re: Input Issues

    Answer
    Reply Quote

    Yes,

    The first example works, just not correctly. It has it either moving or jumping; just not both. The second example won't even fire for some reason.

    EDIT:Figured it out, was using a series of else if's to check different key presses and forgot that a chain of if elses under and if statement only applies to the first if, and it was assuming all was well after the first if and skipping the rest.

  • 24/03/2008 15:31 In reply to

    Re: Input Issues

    Zeriku:

    EDIT:Figured it out, was using a series of else if's to check different key presses and forgot that a chain of if elses under and if statement only applies to the first if, and it was assuming all was well after the first if and skipping the rest.

    Meaning, the code you posted wasn't what you were actually using? There's not much chance of us helping out in that case.

    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 24/03/2008 18:06 In reply to

    Re: Input Issues

    Look, it was 3am in the morning and I was trying to get something out before I went to bed. I said I figured it out, why post in this thread just to bash me for not posting the original code?
  • 24/03/2008 18:32 In reply to

    Re: Input Issues

    Zeriku:
    Look, it was 3am in the morning and I was trying to get something out before I went to bed. I said I figured it out, why post in this thread just to bash me for not posting the original code?


    He wasn't bashing you, he is trying to explain that if you don't post your actual code we can't help. The code you give us has to be the same thing you are looking at otherwise you might miss typos or other little things. He was simply saying that next time you post code you should do a direct copy/paste from your code rather than typing in something that's similar.
  • 25/03/2008 9:27 In reply to

    Re: Input Issues

    Zeriku:
    Look, it was 3am in the morning and I was trying to get something out before I went to bed. I said I figured it out, why post in this thread just to bash me for not posting the original code?

    The people around here don't generally bash.  ;-)  The fastest way to post your code is to copy and paste...

  • 25/03/2008 9:39 In reply to

    Re: Input Issues

    Nick Gravelyn:
    Zeriku:
    Look, it was 3am in the morning and I was trying to get something out before I went to bed. I said I figured it out, why post in this thread just to bash me for not posting the original code?


    He wasn't bashing you, he is trying to explain that if you don't post your actual code we can't help. The code you give us has to be the same thing you are looking at otherwise you might miss typos or other little things. He was simply saying that next time you post code you should do a direct copy/paste from your code rather than typing in something that's similar.

    Exactly. Notice that question mark at the end of the first sentence in my previous post? That means I'm asking if that's the case, not bashing. :)

    Help us help you. As has been stated copy and paste your code, don't retype it. That way we're both looking at the same thing.

    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
Page 1 of 1 (8 items) Previous Next