Results 1 to 2 of 2
  1. #1
    Dommie is offline Member
    Join Date
    Aug 2014
    Rep Power

    Default How to make moving by alternating arrow keys ?

    Hi, I've started creating a simple game in Java, but I'm still a beginner, so now I'm stucked. I wanted to make moving character by fast alternating arrow keys, but I don't know how. I can make a boolean variable, which disables moving by pressing the same key again, but the player can just hold the key and character is still moving. I thought about changing position of character when the key is pressed, instead of increasing speed, but then the movement wouldn't be smooth. I think this may sound incomprehensible, so I will add a link to game like an example of what I mean. I will appreciate any help !

    Play Mini Sports Challenge game online - Y8.COM

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: How to make moving by alternating arrow keys ?

    This is in the area of what I would refer to as advanced intermediate Java programming. For a new programmer
    it could be a little frustrating to get it to work. This type of control is probably best handled by having a key press
    start the motion and have a timer make the moves for you as long as the key is pressed. When the key is released
    the motion stops. This tends to avoid lag times which occur when holding the key down to initiate the repeating
    key mode. There have been discussions about this on this forum so if you do a site search with your favorite browser
    you should find some helpful threads.

    Last edited by jim829; 08-03-2014 at 09:30 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Etch A Sketch Like Program Using Arrow Keys
    By jmanes92 in forum AWT / Swing
    Replies: 6
    Last Post: 04-24-2012, 11:35 PM
  2. Replies: 4
    Last Post: 12-03-2011, 04:38 PM
  3. how to move a rectangle with arrow keys,
    By jmu2101 in forum AWT / Swing
    Replies: 3
    Last Post: 09-27-2011, 01:13 AM
  4. Arrow Keys?
    By Alerhau in forum New To Java
    Replies: 10
    Last Post: 06-17-2011, 07:45 PM
  5. Moving a ball with Arrow Keys
    By kekcklemen in forum Java Applets
    Replies: 5
    Last Post: 02-25-2011, 10:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts