dpad events' handle frequency


Last Updated:

  1. mrqs

    mrqs Well-Known Member This Topic's Starter

    Joined:
    Sep 28, 2009
    Messages:
    1,446
    Likes Received:
    92
    what i have now is a onKeyDown() in a SurfaceView and the d-pad works much like the windows arrow keys in a text field - when you press-and-hold left, the cursor moves 1 step, pauses, then moves n steps per second until you release the button

    this is of course useful for textfields and such, but when you want to control the position of an object on screen (such as a character in a game) it's not so good

    so how do you overcome this?
    how do you generate the n events per second from the moment you down the d-pad button?
     

    Advertisement
  2. leebanfield

    leebanfield Member

    Joined:
    Apr 20, 2010
    Messages:
    5
    Likes Received:
    1
    I haven't been programming with android long but you could start a movement with the onkeydown() and one stop the movement when you get a onKeyUp().

    the repeating of the onkeydown() shouldn't cause a problem if the movement action is contained within a controlled f loop.

    Could use java.util.Timer object to make the next movement event.
     
    mrqs likes this.
  3. mrqs

    mrqs Well-Known Member This Topic's Starter

    Joined:
    Sep 28, 2009
    Messages:
    1,446
    Likes Received:
    92
    good point, should have thought of that myself - thanks :)
     

Share This Page

Loading...