Why isn't view.invalidate immediately redrawing the screen in my android game

前端 未结 4 2006
抹茶落季
抹茶落季 2020-12-08 16:25

I am trying to make an android game.

I have a game class that extends activity and handles all the user input. Then I have a missionView class that extends view and

4条回答
  •  生来不讨喜
    2020-12-08 17:28

    View#invalidate tells the system to redraw (via onDraw) the view as soon as the main thread goes idle. That is, calling invalidate schedules your view to be redrawn after all other immediate work has finished. If the code in your Game class is being called from the main thread and it puts that thread to sleep, you aren't just pausing rendering, you are pausing input processing all together (usually a bad idea). As a rule of thumb, never sleep a thread that you didn't spawn yourself unless you know what you are doing.

    If you'd like to have your game logic periodically delay using Thread#sleep then run it in a separate thread and use view.postInvalidate() to signal the main thread to wake up and call onDraw.

提交回复
热议问题