自己整理的粒子系统管理,是不是太简单了?
LibParticle.java
package game.pak;
import java.util.ArrayList;
import android.util.Log;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class LibParticle {
public static SpriteBatch ParticleBatch;
// BitmapFont bf;
public static ParticleEffect particle;
public static ParticleEffect tem;
public static ParticleEffectPool particlepool;
public static ArrayList<ParticleEffect> particlelist;
public static float initX=0;
public static float initY=0;
public static float ParticleX=0;
public static float ParticleY=0;
public static float XX=0;
public static float YY=0;
public LibParticle(SpriteBatch batch,String resource){
ParticleBatch=batch;
particle = new ParticleEffect();
particle.load(Gdx.files.internal(resource/*"test.p"*/), Gdx.files.internal(""));
particlepool=new ParticleEffectPool(particle, 5, 10);
particlelist=new ArrayList<ParticleEffect>();
}
//增加粒子
public static void addParticle(float x,float y){
initX=x;
initY=y;
tem=particlepool.obtain();
tem.setPosition(x,800-y);
particlelist.add(tem);
}
//绘制
public void drawParticle(){
ParticleBatch.begin();
float aa=Gdx.graphics.getDeltaTime();
for(int i=0;i<particlelist.size();i++){
particlelist.get(i).draw(ParticleBatch, Gdx.graphics.getDeltaTime());
}
ParticleBatch.end();
}
public void set_position(float x,float y){
this.ParticleX=x;
this.ParticleY=Gdx.graphics.getHeight()-y;
for(int i=0;i<particlelist.size();i++){
particlelist.get(i).setPosition(ParticleX,ParticleY);
}
}
//释放
public void disParticle(){
ParticleEffect temparticle;
for(int i=0;i<particlelist.size();i++){
temparticle=particlelist.get(i);
if(temparticle.isComplete()){
particlelist.remove(i);
}
}
}
}