Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  pressing keys rapidely, continously - game stucks  (Read 563 times)
0 Members and 1 Guest are viewing this topic.
Offline markymark

JGO Visitor



Java games rock!


« Posted 2005-03-05 15:30:10 »

Hi, I have a problem with a game I am programming.
An essential part of it is to make a wheel (a loaded image) turn as fast as possible. An user can do this
by pressing the 4 arrow-keys, one-after-another.
(this is supposed to simulate the "winding" of a real wheel). After about two minutes of gaming, before that everything is fine, suddenly the sprites on screen dont
move evenly anymore, they move jerky or seem to jump. Obviously this happens because the computer
isnt able to run the gameloop smoothly anymore.
But why is that?
I suspect that java cant handle the heavy, unusual
keyboard input of my game at some point, because the
going-jerky always happens while really torturing the
arrow-keys. Of course it could also be that java has a problem with rotating my wheel image so fastly(its 276 by 277 pixels, see my implementation). However I did a test rotating the same image fastly without keyboard input and this worked fine.

So I would be grateful for any suggestions.
In my code-examples I included, hopefully, all the relevant bits.

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  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
// the wheel-image is loaded into an image object
wheel = toolkit.getImage("C:/Programme/java/j2re1.4.2_01/Rad/"wheel.gif");


// inside the paint method, the wheel is drawn
//onto java2D context, I use double buffering
//positions[0] is an AffineTransform Object

g2.drawImage(wheel,positions[0],this);



//this is how the keyboard input is analyzed
boolean[] keysPressed = new boolean[256];

 class Tastenlauscher extends KeyAdapter
 {




              public void keyPressed(KeyEvent e)
              {
              keysPressed[e.getKeyCode()] = true;
                            }


              public void keyReleased(KeyEvent e)
              {
             keysPressed[e.getKeyCode()] = false;
               }



   }

// the following part is inside the gameloop
// here two variables are important, the
//one, called "
increaser", is connected to the
//keyboard values:                  
                 
                  if(keysPressed[37])
                    increaser = 4;

                  if(keysPressed[38])
                    increaser = 3;

                  if(keysPressed[39])
                    increaser = 2;

                  if(keysPressed[40])
                    increaser = 1;


// the value of increaser is written to the
//second variable, called "
previouskey",
// but only after an if-statement has checked, if
//the value of the current keyboardinput
// is in an favourable way different from  the last
//input("
previouskey")
// if this is true, another variable, acceleration, is
// set to a value, if not it
// remains 0. The acceleration variable is
//then analyzed by an algorythm (not posted here)
// and translated into the rotaion angle of
//the Affinetransform Object positions[0]  


if    ((((previouskey == 1) && (increaser == 2)) || ((increaser == 3) && (previouskey == 2)) || ((previouskey == 3 && increaser == 4)) ||
 ((previouskey == 4 && increaser == 1))))
                      {


                              acceleration = (0.0002);




                              bremse = 0;
                              bremse0 = false;


                       }
                       else
                       {
                              bremse0 = true;

                              acceleration = 0;

                              bremse++;
                        }
 

                 vorigetaste = increaser;
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (144 views)
2013-05-17 21:29:12

alaslipknot (152 views)
2013-05-16 21:24:48

gouessej (183 views)
2013-05-16 00:53:38

gouessej (177 views)
2013-05-16 00:17:58

theagentd (187 views)
2013-05-15 15:01:13

theagentd (172 views)
2013-05-15 15:00:54

StreetDoggy (215 views)
2013-05-14 15:56:26

kutucuk (240 views)
2013-05-12 17:10:36

kutucuk (238 views)
2013-05-12 15:36:09

UnluckyDevil (244 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.15 seconds with 20 queries.