Question

I followd this tutorials on particle effect for memory management particle effect tutorial im having a problem with obtaining the effect

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();

}

}

dont bother with some codes, the problem is the particle effcet, cant draw particles on scren.

any help would be much appreciated, Dave

Was it helpful?

Solution

I think the problem is the line:

particleEffect.getEmitters().clear();

You're loading your particle effect and then removing (cleaning) all emitters. After that, the particle effect doesn't have any information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top