当前位置: 代码迷 >> Android >> android中canvas.clipRect建立卡通
  详细解决方案

android中canvas.clipRect建立卡通

热度:47   发布时间:2016-05-01 19:36:09.0
android中canvas.clipRect建立动画

看了MOMO的游戏界面关闭的特效后,想想,做了个游戏界面开始的动画效果,原理主要是利用裁剪图的

canvas.clipRect方法的应用

效果截图:

?

未相交之前:

?

相交之后:

?

主要的代码如下:

?

// 建立遮罩效果动画	private void drawClip(Canvas canvas) {		// 动画完成时,把整张图片显示出来		if (isStop3) {			canvas.drawBitmap(bitmap, 0, 0, null);			return;		}		// 当进行到当完成,将动画停止,但别忘了把背景图片显示出来		if (steep30 >= viewW && viewW != 0) {			steep30 = 0;			steep31 = 0;			isStop3 = true;			canvas.drawBitmap(bitmap, 0, 0, null);			return;		}		// 20开始		for (int i = 0; i <= viewH; i = i + 40) {			// 创建从左到右的遮罩动画			clip(canvas, bitmap, steep30, 20, 0, i);			// 创建从右到左的遮罩动画			clip(canvas, bitmap, steep31, 20, viewW - steep31, i + 20);		}		// 运行一次遮罩动画前进行距离		steep30 += 5;		steep31 += 5;	}//进行图片裁剪private void clip(Canvas canvas, Bitmap bit, int w, int h, int posX,			int posY) {		canvas.save();		canvas.clipRect(posX, posY, posX + w, posY + h);		canvas.drawBitmap(bit, 0, 0, null);		canvas.restore();	}
  相关解决方案