Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Still trouble with choppy input  (Read 1914 times)
0 Members and 2 Guests are viewing this topic.
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Posted 2003-11-04 07:55:33 »

I'm still having problems where my input handler for keyboard input is firing for no keys pressed. Even If I am holding down a key. I think windows is firing repeating pressed/released events. This causes my sprite to stop during some frames and move during others. Here is my code.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
public void processKeyEvent(KeyEvent ke) 
    {
        controls[ke.getKeyCode()&0xFF] = (ke.getID()==KeyEvent.KEY_RELEASED)?0:1 ;                
    }

private void updateInput()
    {      
//        if(state == PLAY)
//        {
            if(controls[KeyEvent.VK_UP] == 1)
            {
                diry = -2;
                dirx = 0;
                hero.setDirection(Hero.UP);            
                hero.start();
            }            
            else if(controls[KeyEvent.VK_DOWN] == 1)
            {
                diry = 2;
                dirx = 0;
                hero.setDirection(Hero.DOWN);
                hero.start();
               
            }
            else if(controls[KeyEvent.VK_LEFT] == 1)
            {
                dirx = -2;
                diry = 0;
                hero.setDirection(Hero.LEFT);
                hero.start();
   
            }
            else if(controls[KeyEvent.VK_RIGHT] == 1)
            {
                dirx = 2;
                diry = 0;
                hero.setDirection(Hero.RIGHT);
                hero.start();
               
            }
            else
            {
                dirx = 0;
                diry = 0;              
               // hero.stop();
            }
           
            if(controls[KeyEvent.VK_ESCAPE] == 1) running = false;
}


I call updateInput() every frame.

If I remove the block for the last else everything is smooth as glass. :-/

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2003-11-04 08:02:47 »

Pretty similar to what I'm doing for a bunch of things..

What does hero.start() do ?

Kev

Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #2 - Posted 2003-11-04 10:18:19 »

Hero.start() sets the Hero's animated flag to true, it doesn't move the Hero or anything like that.

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2003-11-04 10:25:45 »

I assume you've already done this, but you could stick some debug in the processKeyEvent to see whats happening.

Kev

Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #4 - Posted 2003-11-04 10:35:34 »

I just thought of something.... How does unix handle a key being held down.
I'm actually running on windows running on a sunpci card on a solaris box.

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2003-11-04 15:33:45 »

I dunno about Solaris but I know for Linux you need to play with the key repeat (I think it was either enable or disable and it wasn't obvious which one you wanted.  In fact I think you wanted to Disable because otherwise X starts ignoring it as a "stuck key" but I could be mis-remebering.)

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #6 - Posted 2003-11-04 16:56:16 »

Quote
I dunno about Solaris but I know for Linux you need to play with the key repeat (I think it was either enable or disable and it wasn't obvious which one you wanted.  In fact I think you wanted to Disable because otherwise X starts ignoring it as a "stuck key" but I could be mis-remebering.)



disable via which api jeff?

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2003-11-04 23:08:10 »

Linux command line.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline jtr

Senior Newbie




I love YaBB 1G - SP1!


« Reply #8 - Posted 2003-11-05 00:48:36 »

You may want to check out
http://developer.java.sun.com/developer/bugParade/bugs/4504217.html

and vote for it. (I think you're looking for "xset r off")
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #9 - Posted 2003-11-05 08:48:11 »

Quote
You may want to check out
http://developer.java.sun.com/developer/bugParade/bugs/4504217.html

and vote for it. (I think you're looking for "xset r off")



I voted for it. xset r off only appears to affect the current window on solaris though.

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (150 views)
2017-09-30 02:57:34

theagentd (225 views)
2017-09-26 18:23:31

cybrmynd (304 views)
2017-08-02 12:28:51

cybrmynd (291 views)
2017-08-02 12:19:43

cybrmynd (300 views)
2017-08-02 12:18:09

Sralse (292 views)
2017-07-25 17:13:48

Archive (980 views)
2017-04-27 17:45:51

buddyBro (1106 views)
2017-04-05 03:38:00

CopyableCougar4 (1685 views)
2017-03-24 15:39:42

theagentd (1433 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!