/**
* 特效类,切割逐帧图,通过逻辑函数控制播放帧
* @author 老衲玩IT
*
*/
public class Effection{
public boolean idDead;
int totalFrame;
int rows,cols;
int currentFrame;
int x,y;
Bitmap bitmap;
int w,h;
int type;
int speed=5;
float r,rad,fixX,fixY;
public Effection(Bitmap bitmap, int x, int y) {
// TODO Auto-generated constructor stub
this.bitmap=bitmap;
this.x=x;
this.y=y;
}
public Effection(Bitmap bitmap, int x, int y,int totalFrame) {
// TODO Auto-generated constructor stub
this.bitmap=bitmap;
this.x=x;
this.y=y;
this.totalFrame=totalFrame;
}
public Effection(Bitmap bitmap, int x, int y,int rows,int cols,int totalFrame) {
// TODO Auto-generated constructor stub
this.bitmap=bitmap;
this.x=x;
this.y=y;
this.rows=rows;
this.cols=cols;
this.totalFrame=totalFrame;
this.w=bitmap.getWidth()/cols;
this.h=bitmap.getHeight()/rows;
// this.type=type;
// if(type==2){
// this.fixX=this.x;
// this.fixY=this.y;
// }
}
public void draw(Canvas canvas, Paint paint) {
// TODO Auto-generated method stub
canvas.save();
canvas.clipRect(x, y, x+w, y+h);
canvas.drawBitmap(bitmap, x-((currentFrame)/4%cols)*w,y-((currentFrame)/4/cols)*h , paint);//三倍延时
canvas.restore();
}
public void logic() {
currentFrame++;
if(currentFrame>=totalFrame*4){
//this.idDead=true;
this.idDead=true;//消亡
}
}
}
/**
* 管理2D特效
* @author 老衲玩IT
*
*/
public class EffectManager {
private static Vector<Effection> vcEffections=new Vector<Effection>();
public static void addEffect(Effection ef) {
vcEffections.add(ef);
}
public static void logic(){
for (int i = 0; i < vcEffections.size(); i++) {
Effection ef=vcEffections.get(i);
if (ef.idDead) {
vcEffections.removeElement(ef);
}else {
ef.logic();
}
}
}
public static void draw(Canvas canvas,Paint paint){
for (int i = 0; i < vcEffections.size(); i++) {
vcEffections.get(i).draw(canvas, paint);
}
}
}
|