0
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ Render your text using OpenGL instead of using a TextView. Have a look at this question on SO. The same goes for other views. To get the best performance, render everything to the GLSurfaceView. \$\endgroup\$ – free3dom Jun 2 '14 at 7:41
  • \$\begingroup\$ @free3dom Thanks for your comment. The lack of support for rendering texts is the reason I chose using TextViews, but it seems that there aren't many advantages in this approach. :( I'll probably have to go back to OpenGL. \$\endgroup\$ – async Jun 2 '14 at 21:14
  • \$\begingroup\$ The lack of native text rendering in OpenGL is very annoying, but once you have a system in place it is really quite painless :) I wrote a tutorial on doing this using OpenGL ES 1.0 and it was ported to OpenGL ES 2.0 here. \$\endgroup\$ – free3dom Jun 2 '14 at 23:02
  • \$\begingroup\$ @free3dom Ha, I didn't realize it was your tutorial <I actually first read it a while ago>. Nice job! Will look at using that soon. :) \$\endgroup\$ – async Jun 3 '14 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.