我遵循了关于内存管理的粒子效应的教程particle effect tutorial 我有一个获得效果的问题
public class GameTouch implements Touchable, Disposable {
private OrthographicCamera cam;
private SpriteBatch batch;
public SwipeHandler swipe;
private Texture tex;
private ShapeRenderer shapes;
private SwipeTriStrip tris;
private ParticleEffect particleEffect;
private Array<PooledEffect> effects;
private ParticleEffectPool pool;
public GameTouch(){
create();
}
@Override
public void create() {
// TODO Auto-generated method stub
//the triangle strip renderer
tris = new SwipeTriStrip();
//tchikenss of line
tris.thickness = 30f;
//a swipe handler with max # of input points to be kept alive
swipe = new SwipeHandler(10);
//minimum distance between two points
swipe.minDistance = 10;
//minimum distance between first and second point
swipe.initialDistance = 10;
//we will use a texture for the smooth edge, and also for stroke effects
tex = new Texture(Gdx.files.internal("data/gradient.png"));
tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
shapes = new ShapeRenderer();
batch = new SpriteBatch();
cam = new OrthographicCamera();
cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
particleEffect = new ParticleEffect();
particleEffect.load(Gdx.files.internal("data/particles/particle.p"), Gdx.files.internal("data/particles"));
particleEffect.getEmitters().clear();
effects = new Array<PooledEffect>();
pool = new ParticleEffectPool(particleEffect, 1 , 2);
}
@Override
public void resize(float width, float height) {
// TODO Auto-generated method stub
}
@Override
public void update(float delta) {
// TODO Auto-generated method stub
//Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(!swipe.isDrawing)
return;
cam.update();
batch.setProjectionMatrix(cam.combined);
Gdx.gl.glEnable(GL20.GL_BLEND);
//Gdx.gl.glHint(GL20.GL_TRIANGLE_STRIP, GL20.GL_NICEST);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
tex.bind();
//the endcap scale
tris.endcap = 5f;
//the thickness of the line
tris.thickness = 30f;//(float)Gdx.graphics.getHeight() / 28f;
//generate the triangle strip from our path
tris.update(swipe.path());
//the vertex color for tinting, i.e. for opacity
tris.color = SettingsManager.color;
//render the triangles to the screen
tris.draw(cam);
batch.begin();
if(swipe.path().size > 0){
// the problem is here , it wont add in the effects array.. size is always 0
PooledEffect effect = pool.obtain();
effect.setPosition(swipe.path().get(0).x, swipe.path().get(0).y);
effects.add(effect);
for(int i = 0 ; i < effects.size ; i ++){
PooledEffect pooledEffect = effects.get(i);
pooledEffect.draw(batch , delta);
if(pooledEffect.isComplete()){
pooledEffect.free();
effects.removeIndex(i);
}
}
}
batch.end();
}
@Override
public void dispose() {
// TODO Auto-generated method stub
shapes.dispose();
tex.dispose();
}
}
不要打扰一些代码,问题是粒子效应,不能在scren上绘制粒子。
任何帮助将不胜感激, 戴夫
答案 0 :(得分:0)
我认为问题在于:
particleEffect.getEmitters().clear();
您正在加载粒子效果,然后移除(清洁)所有发射器。之后,粒子效果没有任何信息。