-
keyup, keydown
We're am currently tinkering with Mike Hall's old Asteroid code and we're trying to take out the deprecations and we ran into a few problems.
We could not fix the keyUp and keyDown deprecations. Our code for keyUp was:
public boolean keyUp(Event e, int key) {
// Check if any cursor keys where released and set flags.
if (key == Event.LEFT)
left = false;
if (key == Event.RIGHT)
right = false;
if (key == Event.UP)
up = false;
if (key == Event.DOWN)
down = false;
if (!up && !down && thrustersPlaying) {
thrustersSound.stop();
thrustersPlaying = false;
}
return true;
}
When we try and change keyUp to something else, you cannot press a button more than once while running the program.
The code for keyDown is:
public boolean keyDown(Event e, int key) {
// Check if any cursor keys have been pressed and set flags.
if (key == Event.LEFT)
left = true;
if (key == Event.RIGHT)
right = true;
if (key == Event.UP)
up = true;
if (key == Event.DOWN)
down = true;
if ((up || down) && ship.active && !thrustersPlaying) {
if (sound && !paused)
thrustersSound.loop();
thrustersPlaying = true;
}
When we try and change keyDown, the program won't even start.
Can anyone help us?
-
Should you not upgrade to keyListener callbacks like keyPressed, keyReleased & keyTyped and sort out the up/down/left/right there ?
eschew obfuscation
-
For some reason, that doesn't work. I still have the same problem.
-
If the program "leaves" when you use these keys it could be a traversal-
key messup, - keys that remove the focus from one component to another
like the tab often does. There are ways to override/block such traversals
but I would have to see the code in order to say any more specific about
that'
If the old code has some exotic workarounds for old event/thread quirks, or
whatevver, then its bad news, but it can be solved.
Last edited by sjalle; 06-03-2005 at 05:43 PM.
eschew obfuscation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks