dpad events' handle frequency

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

  1. 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
    26

    Apr 20, 2010
    5
    1
    26
    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. good point, should have thought of that myself - thanks :)
     

Share This Page

Loading...