-
Notifications
You must be signed in to change notification settings - Fork 21
/
Boom.java
39 lines (36 loc) · 1.04 KB
/
Boom.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.pg;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
public class Boom {
private Bitmap bmpBoom;//爆炸效果资源图
private int boomX, boomY;//爆炸效果的位置坐标
private int cureentFrameIndex;//爆炸动画播放当前的帧下标
private int totleFrame;//爆炸效果的总帧数
private int frameW, frameH;//每帧的宽高
public boolean playEnd;//是否播放完毕,优化处理
//爆炸效果的构造函数
public Boom(Bitmap bmpBoom, int x, int y, int totleFrame) {
this.bmpBoom = bmpBoom;
this.boomX = x;
this.boomY = y;
this.totleFrame = totleFrame;
frameW = bmpBoom.getWidth() / totleFrame;
frameH = bmpBoom.getHeight();
}
//爆炸效果绘制
public void draw(Canvas canvas, Paint paint) {
canvas.save();
canvas.clipRect(boomX, boomY, boomX + frameW, boomY + frameH);
canvas.drawBitmap(bmpBoom, boomX - cureentFrameIndex * frameW, boomY, paint);
canvas.restore();
}
//爆炸效果的逻辑
public void logic() {
if (cureentFrameIndex < totleFrame) {
cureentFrameIndex++;
} else {
playEnd = true;
}
}
}