游戏中进度条的简单实现

第一种:       
      private void myDraw() {
			 try{
				 canvas = sfh.lockCanvas();
				 if(canvas != null){
					 canvas.drawColor(Color.CYAN);
					 canvas.save();
					 canvas.clipRect(new Rect(10, screenH/2, currentX, ((screenH/2)+bitmapPass.getHeight())));
					 canvas.drawBitmap(bitmapPass, 10, screenH/2, paint);
					 canvas.restore();
//					 canvas.drawBitmap(bitmapBg, currentX, screenH/2, paint);
				 }
			 }catch (Exception e) {
				 e.printStackTrace();
			}finally{
				if(canvas != null){
					sfh.unlockCanvasAndPost(canvas);
				}
			}
			 
		}

		private void logic() {
			if(currentX > 10){
				currentX-=2;
			}else {
				currentX = 10;
				return;
			}
			
		}
第二种:
//		private void myDraw() {
//			try{
//				canvas = sfh.lockCanvas();
//				if(canvas != null){
//					canvas.drawColor(Color.CYAN);
//					canvas.drawBitmap(bitmapPass, 10, screenH/2, paint);
//					canvas.drawBitmap(bitmapBg, currentX, screenH/2, paint);
//				}
//			}catch (Exception e) {
//				e.printStackTrace();
//			}finally{
//				if(canvas != null){
//					sfh.unlockCanvasAndPost(canvas);
//				}
//			}
//			
//		}
//		
//		private void logic() {
//			if(currentX > 10){
//				currentX-=2;
//			}else {
//				currentX = 10;
//				return;
//			}
//			
//		}

这里地两种不同的方式,第一种少用一张图片

你可能感兴趣的:(游戏,android,进度条)