![]() Also, unlocking and posting the canvas was fast on an emulator for small screens (1 ms), very slow on an emulator for large screens (40 ms), and fast on all real devices that I have tested (Samsung Galaxy Tab, Lenovo P1c72, Samsung DUOS, Alcatel).On the other hand, on a Lenovo P1c72 (1920×1080) is was 1ms – it seems not to be related to the screen resolution. I’ve noticed that locking the canvas was very fast on different emulators (about 1 ms, from small screens to large screens), but on a real Samsung Galaxy Tab (1280×800) it’s about 9 ms.The results were surprising and may help you to understand why your game is slow under certain conditions: In the process of increasing the frame rate of my game, I implemented various timers to carefully check the speed of locking the canvas, updating the scene, drawing the scene, and unlocking/posting the canvas. You can allow the drawing code to skip a frame once in a while, but you cannot allow the scene update code to do so. Assuming that the update code is very fast (a few milliseconds per frame) compared to the drawing code, this may indeed be useful. After all, to give the game a consistent speed it’s necessary to update the scene at a stable frame rate (say, exactly 60 times per second) because moving objects that speed up or slow down hurt the player’s game experience. ![]() ![]() Some people separate the scene update code from the scene drawing code (in another thread). This method repeatedly does the following: The dedicated thread for your game loop executes the run() method. There are lots of examples on the web of standard game loops, and they tend to look like this: public void run () Most likely, your game will have a game loop that runs as a separate thread. In this article on speeding up Canvas.drawBitmap, I’d like to point out some pitfalls you can avoid, based on my own experience developing an app with heavy canvas drawing. You’ll also find that your game runs fast on some devices, and slowly on others (in particular, phones versus tablets). You also may have noticed that as your number of bitmaps per frame increases, your framerate drops significantly, to the point of your game becoming unplayable. If you’re developing a game for Android that uses canvas drawing, you’re probably calling Canvas.drawBitmap to draw many bitmaps to the screen.
0 Comments
Leave a Reply. |