import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.view.SurfaceHolder;
import com.pm_road.fireair.bean.Bullet;
/**
* 爆炸线程
*
* @ClassName: BoomRunnable
* @Description: 爆炸线程
* @author lipeng
* @date 2014-11-5 下午02:43:39
*
*/
public class BoomRunnable implements Runnable {
private Bullet bullet;// 当前的子弹
private Context context;// 上下文
private SurfaceHolder holder;
public BoomRunnable(Context context,SurfaceHolder holder) {
super();
this.context = context ;
this.holder = holder;
}
@Override
public void run() {
Canvas canvas = holder.lockCanvas();
canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
//碰撞效果
canvas.drawLine(bullet.getX()-10, 2, bullet.getX()-15, 10, paint);
canvas.drawLine(bullet.getX()-15, 10, bullet.getX()-10, 12, paint);
canvas.drawLine(bullet.getX()-10, 12, bullet.getX()-13, 20, paint);
canvas.drawLine(bullet.getX()-13, 20, bullet.getX(), 12, paint);
canvas.drawLine(bullet.getX(), 12, bullet.getX()+13, 20, paint);
canvas.drawLine(bullet.getX()+13, 20, bullet.getX()+10, 12, paint);
canvas.drawLine(bullet.getX()+10, 12, bullet.getX()+15, 10, paint);
canvas.drawLine(bullet.getX()+15, 10, bullet.getX()+10, 2, paint);
holder.unlockCanvasAndPost(canvas);
}
public Bullet getBullet() {
return bullet;
}
public void setBullet(Bullet bullet) {
this.bullet = bullet;
}
}
写完实体类和线程之后,就应该把他和安卓的xml 进行结合。结合代码:
本文章属于原创性文章,珍惜他人劳动成果,转载请注明出处: