Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid touch input delay problems for a timing critical game. Is there a delay before onTouchEvent is called?
    primarykey
    data
    text
    <p>So we're working on the android version of the iPhone game Snake Race (it's a cool game). However, we seem to be getting a delay on the touch inputs just big enough to make a difference. (The snake might turn a step later than you intended) After getting almost used to the android version, the iPhone version feels like a blessing. </p> <p>The question is whether there is a delay from androids side in calling the onTouchEvent() method? (I'm using Samsung Galaxy S2) If so, is there any neat tricks to circumvent the issue?(Even if it means using the NDK)</p> <p>This is the current implementation touch handling:</p> <pre><code>public boolean onTouchEvent(final MotionEvent event) { int action = event.getAction(); if(action == MotionEvent.ACTION_DOWN || (action &amp; MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN){ Run run = GameVars.run; if(run != null){ if(run.paused){ run.paused = false; }else{ if(event.getX(action &gt;&gt; MotionEvent.ACTION_POINTER_ID_SHIFT) &lt; GameVars.width/2){ run.addTap(-1); }else{ run.addTap(1); } } } return true; } return false; } </code></pre> <p>This is the addTap method:</p> <pre><code>public void addTap(int newDir) { if(newDir == -tapDir){ taps++; tapDir *= -1; } } </code></pre> <p>And then every frame, taps is checked, and if it's greater than zero (and we're allowed to turn atm) we turn. </p> <p>It all works fine and is reliable, but there is a consistent delay (maybe 2-3 frames, which is enough to make the iPhone snake seriously more maneuverable).</p> <p>Any feedback is apprieciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload