What is double buffer technology? The dual-buffer technology means that after the user operation interface is complete, a buffer zone will be provided to save the user operation results.
Why is dual-buffer technology used? For android game development, the UI is all re-painted every time, so it is said that there is a new image, and the old one is gone, so we need to use the dual-buffer technology to save the previous content.
How to implement dual buffering? Use a bitmap object to retain the previous canvas.
Package COM. example. phonegaptest; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmap. config; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. path; import android. util. attributeset; import android. view. motionevent; import android. view. view; public class drawview extends view {float prex; float prey; private Path; Public paint = NULL; Final int view_width = 320; Final int view_height = 480; bitmap cachebitmap = NULL; canvas cachecanvas = NULL; Public drawview (context, attributeset) {super (context, set); cachebitmap = bitmap. createbitmap (view_width, view_height, config. argb_8888); cachecanvas = new canvas (); Path = New Path (); cachecanvas. setbitmap (cachebitmap); paint = new paint (paint. dither_flag); paint. setcolor (color. red); paint. setstyle (paint. style. stroke); paint. setstrokewidth (1); paint. setantialias (true); paint. setdither (true) ;}@ overridepublic Boolean ontouchevent (motionevent event) {float x = event. getx (); float y = event. gety (); Switch (event. getaction () {Case motionevent. action_down: path. moveTo (x, y); prex = x; prey = y; break; Case motionevent. action_move: path. quadto (prex, prey, x, y); prex = x; prey = y; break; Case motionevent. action_up: cachecanvas. drawpath (path, paint); Path. reset (); break;} invalidate (); Return true ;}@ overrideprotected void ondraw (canvas) {super. ondraw (canvas); paint BMP paint = new paint (); canvas. drawbitmap (cachebitmap, 0, 0, BMP paint); canvas. drawpath (path, paint );}}