Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2005

Tip: Looking for answers? Try searching our database.

Multiple Input From Keyboard at Once?

Thread view: 
caleb - 19 Jul 2005 06:09 GMT
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 - 19 Jul 2005 21:13 GMT
hiwa - 20 Jul 2005 03:43 GMT
> 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
[quoted text clipped - 3 lines]
> 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.
caleb - 31 Jul 2005 20:14 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.