Multiple Input From Keyboard at Once?

Discussion in 'Java' started by caleb, Jul 19, 2005.

  1. caleb

    caleb Guest

    I'm making a Mario like side scroller game and I having some trouble
    with input. I can only hit one key at once, if I try two it doesn't
    register. I would like to be able to run and jump at the same time.

    public void keyPressed(KeyEvent e) {
    if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
    for(int i=0; i<player.size(); i++) {
    Player p = (Player) player.elementAt(i);
    p.moveEast();
    }
    }
    if(e.getKeyCode() == KeyEvent.VK_LEFT) {
    for(int i=0; i<player.size(); i++) {
    Player p = (Player) player.elementAt(i);
    p.moveWest();
    }
    }
    if(e.getKeyCode() == KeyEvent.VK_SPACE) {
    for(int i=0; i<player.size(); i++) {
    Player p = (Player) player.elementAt(i);
    p.jump();
    }
    }
    }

    This is an example of the kind of thing I'm trying to do. Also I've
    been trying to figure out how to have the camera center on the
    player... so the player's pixels aren't actually moving, but rather the
    background. I assume I should make the input keys move the background
    while the character is only being animated but I haven't started coding
    it yet. Any source code from similar games would be very helpful.
    Thanks in advance.
     
    caleb, Jul 19, 2005
    #1
    1. Advertising

  2. caleb

    caleb Guest

    bump
     
    caleb, Jul 19, 2005
    #2
    1. Advertising

  3. caleb

    hiwa Guest

    "caleb" <> wrote in message news:<>...
    > I'm making a Mario like side scroller game and I having some trouble
    > with input. I can only hit one key at once,
    > if I try two it doesn't

    Simply you can't. Except some modifier keys.

    > This is an example of the kind of thing I'm trying to do. Also I've
    > been trying to figure out how to have the camera center on the
    > player... so the player's pixels aren't actually moving, but rather the
    > background. I assume I should make the input keys move the background
    > while the character is only being animated but I haven't started coding
    > it yet. Any source code from similar games would be very helpful.
    > Thanks in advance.

    That's simple animation task. Examples should abound on the Net.
     
    hiwa, Jul 20, 2005
    #3
  4. caleb

    caleb Guest

    If it's not possible then why do some games allow you to shoot, jump,
    and run at the same time?

    Thanks for the reply though.
     
    caleb, Jul 31, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Shaw
    Replies:
    1
    Views:
    882
    J. Romano
    Nov 10, 2003
  2. Starbase Commander

    Unbuffered keyboard input???

    Starbase Commander, Sep 10, 2004, in forum: Perl
    Replies:
    1
    Views:
    721
    J├╝rgen Exner
    Sep 11, 2004
  3. FabFreddy

    How to receive keyboard input?

    FabFreddy, Nov 25, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    798
    John Timney \( MVP \)
    Nov 25, 2005
  4. Replies:
    4
    Views:
    704
    Walter Roberson
    Sep 9, 2005
  5. Gancy
    Replies:
    4
    Views:
    248
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page