Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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 702 times)
0 Members and 1 Guest are viewing this topic.
Offline markymark

Innocent Bystander




Java games rock!


« Posted 2005-03-05 14: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.

 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (35 views)
2014-12-09 22:41:13

BurntPizza (70 views)
2014-12-08 04:46:31

JscottyBieshaar (32 views)
2014-12-05 12:39:02

SHC (44 views)
2014-12-03 16:27:13

CopyableCougar4 (40 views)
2014-11-29 21:32:03

toopeicgaming1999 (108 views)
2014-11-26 15:22:04

toopeicgaming1999 (94 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!