• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps dpad events' handle frequency

mrqs

Android Expert
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?
 
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.
 
Back
Top Bottom