Android: Understanding OnDrawFrame, FPS and VSync (OpenGL ES 2.0)

后端 未结 1 1763
忘了有多久
忘了有多久 2021-02-07 12:06

For a while now I\'ve experienced an intermittent \'stuttering\' of the sprites that are in motion within my Android Game. It\'s a fiarly simple 2D OpenGL ES 2.0 game. (This is

相关标签:
1条回答
  • 2021-02-07 12:37

    Some thoughts:

    • Don't use System.currentTimeMillis() for timing things. It's based on the wall clock, which can be updated by the network. Use System.nanoTime(), which is based off the monotonic clock.
    • See this appendix for some notes on game loops. Queue-stuffing is fine for many things, but understand that you're not exactly working off of VSYNC, so timings will tend to be inaccurate.
    • Some devices (notably those based on qcom SOCs) reduce CPU speed when they think they're idle. Always take timings while actively moving your finger around on the touch screen.
    • If you want to debug frame rate issues you need to be using systrace. The traceview profiling isn't that useful here.

    See Grafika's "record GL app" Activity for an example of a simple GLES app that drops frames, but adjusts the animation such that it's rarely noticeable.

    0 讨论(0)
提交回复
热议问题