Animation ist only smooth when ontouchevent is called

跟風遠走 提交于 2019-12-08 09:29:07

问题


i'm making my first 2d sidescroller game using a surfaceview and a canvas to draw things on (a lot of primitives put in different path objects). my game loop uses fixed timesteps with linear interpolation. i don't create any objects during the game. i've been improving my code for 3 weeks now, but my animation is still not all the time smooth. it's ok, but every few seconds there are a lot of little hicks for about 1 or 2 seconds. what i recognized is when i move my player (this means touching the screen), the little hicks disappear for as long as i touch the screen and move my player. this means as long as ontouchevent of the surfaceview is called, the animation is smooth. i dont understand this and i want a smooth animation. can somebody help me?


回答1:


This sounds like a known issue on certain devices. See e.g.:

  • Android SurfaceView slows if no touch events occur
  • Animation glitches while rendering on SurfaceView
  • Android thread performance/priority on Galaxy Note 2 when screen is touched/released

The problem is that the system is aggressively reducing clock speeds to save power when it doesn't detect interaction with the user. (Qualcomm in particular seems fond of this.) The workaround is to drop frames when necessary. See this article on game loops, and a Choreographer-based trick demonstrated in Grafika's "record GL app" activity (in doFrame()).



来源:https://stackoverflow.com/questions/31415744/animation-ist-only-smooth-when-ontouchevent-is-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!