Displaying and updating score in Android (OpenGL ES 2)

Posted by user16547 on Game Development See other posts from Game Development or by user16547
Published on 2014-06-01T11:12:23Z Indexed on 2014/06/01 15:58 UTC
Read the original article Hit count: 271

Filed under:
|

I'm using a FrameLayout where I have a GLSurfaceView at the bottom and a few Views on top of it. One of those Views is a TextView that displays the current score.

Here's how I'm updating the score TextView based on what happens in my game loop: whenever an event happens that increases the score, I call activity.runOnUiThread(updater), where activity is the activity that has the above FrameLayout (my main game activity) and updater is just a Runnable that increments the score. From my understanding, using runOnUiThread() from the OpenGL thread is standard practice - otherwise you'll get an exception, I can't remember its name.

The problem is that there's a very noticeable lag between the event and the score update. For example the character gets a coin, but the coin count is not updated quickly. I tried summing all the score events from my game loop and calling runOnUiThread() only once per loop, but it doesn't seem to make much of a difference - the lag is still noticeable.

How can I improve my design to avoid this lag?

© Game Development or respective owner

Related posts about android

Related posts about opengl-es2