質問

Ok, so in creating a game in my spare time, I've been completely stuck when trying to code around the following scenario:

I want to capture tap events (TouchEvent.ACTION_DOWN), and then in 500ms intervals, I want to check to see if the screen is still pressed, and repeat the same action, ad infinitum.

So, I started out with:

switch (myTouchHandler.getAction()) {
  case (TouchEvent.ACTION_DOWN):
  case (TouchEvent.ACTION_MOVE):
    if (inputIntervalTooSoon()) return true;
    //do the magic i intend to do....
 }

....

private boolean inputIntervalTooSoon() {
        final long now = System.currentTimeMillis();
        if ((now - lastTouchEventTime) < 500) return false;
        lastTouchEventTime = now;
        return true;

And this produces the effect that It will wait the 500ms, but it doesn't begin to immediately detect if my finger is still down. It will pick it up again if I move my finger slightly, and then go back to dormant.

If I dont include the Interval function, my action just fires constantly. Any ideas in how to better implement this would be greatly appreciated.

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top