DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: keyup, keydown

  1. #1
    Join Date
    May 2005
    Posts
    3

    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?

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Should you not upgrade to keyListener callbacks like keyPressed, keyReleased & keyTyped and sort out the up/down/left/right there ?
    eschew obfuscation

  3. #3
    Join Date
    May 2005
    Posts
    3
    For some reason, that doesn't work. I still have the same problem.

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links