I wrote a simple Android application that draws a maze using a custom view derived from SurfaceView . It follows the sample LunarLander sample program and performs all calculations and drawings using the background thread directly in the SurfaceHolder object.
Everything is fine and good, and it works well for small / medium-sized mazes, however, if I set the maze cell size to 8 pixels, there will be many cells in the maze executed by the application.
The code does what I donโt like, it draws every cell, even if it hasnโt been changed, and this is necessary to prevent the screen from flickering from the SurfaceView double buffer (in previous iterations of the application, I was only drawing what has changed, and this led to clumsy mess).
Then I want to use SurfaceView , but be more selective about what happens. Is it possible? If not, what are the alternatives? How about saving a bitmap off screen and pulling it selectively into it?
EDIT: I implemented an off-screen combination of Bitmap and Canvas , written by my state machine with a timer, drawing only those areas that were affected during the thread / solution. Then I just draw the entire screen bitmap on the SurfaceView as part of the run() method, and this solved my problem; I can drop the cell size up to 5 pixels and the performance is fine.
trojanfoe
source share