Multiple Input From Keyboard at Once?

C

caleb

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.
 
H

hiwa

caleb said:
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.
 
C

caleb

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top