1. Download our Official Android App: Forums for Android!

Apps dpad events' handle frequency

Discussion in 'Android Development' started by mrqs, Apr 20, 2010.

  1. mrqs

    mrqs Android Expert
    Thread Starter

    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?


  2. leebanfield

    leebanfield Lurker

    Apr 20, 2010
    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 Android Expert
    Thread Starter

    good point, should have thought of that myself - thanks :)

Share This Page