The FPS system
In the case of game development and gaming industry, FPS matters a lot. The game quality measurement depends heavily on the FPS count. In simple words, the higher the FPS of the game, the better. The FPS of a game is dependent on the processing time for instructions and rendering.
It takes some time to execute the game loop once. Let's have a look at a sample implementation of FPS management inside a game loop:
long startTime; long endTime; public final int TARGET_FPS = 60; @Override public void onDraw(Canvas canvas) { if(isRunning) { startTime = System.currentTimeMillis(); //update and paint in game cycle MainGameUpdate(); //set rendering pipeline for updated game state RenderFrame(canvas); endTime = System.currentTimeMillis(); long delta = endTime - startTime; long interval = (1000 - delta)/TARGET_FPS; try { Thread.sleep(interval); } catch(Exception ex) {} invalidate(); } }
In the preceding example...