3
votes

I have created a .p file using Libgdx particle editor by downloading libgdx-nightly-latest.zip using this https://www.youtube.com/watch?v=LCLa-rgR_MA tutorial. Now in my Android project i have added gdx.jar and gdx-backend-android.jar as external jar from Libgdx. I found the following code which are used in libgdx project:

        ParticleEffect effect = new ParticleEffect();
        FileHandle fileDir = Gdx.files.internal("data");
        effect.load(Gdx.files.internal("data/myParticleTxtFile"), fileDir);
        effect.start();

        effect.draw(batch, Gdx.graphics.getDeltaTime());
        batch.end();

I modified the above code as follows in onDraw() method

        ParticleEffect effect = new ParticleEffect();
        FileHandle fileDir = Gdx.files.internal("asset");
        effect.load(Gdx.files.internal("asset/myParticleTxtFile.p"), fileDir);
        effect.start();

        effect.draw((Batch) canvas, Gdx.graphics.getDeltaTime());
        ((Batch) canvas).end();

After debugging the code it is giving null pointer exception Gdx.files.internal("asset") here.I can understand that it is not getting any asset folder but how solve this and how draw particle effect in onDraw() using that .p file in android??

1

1 Answers

0
votes

You can use this way to use .p file in android code

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Particles extends ApplicationAdapter {
SpriteBatch batch;
ParticleEffect pe;

@Override
public void create () {
  batch = new SpriteBatch();

  pe = new ParticleEffect();
  pe.load(Gdx.files.internal("Particles.p"),Gdx.files.internal(""));
        pe.getEmitters().first().setPosition(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
  pe.start();
  }

  @Override
  public void render () {
  Gdx.gl.glClearColor(0, 0, 0, 1);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

  pe.update(Gdx.graphics.getDeltaTime());
  batch.begin();
  pe.draw(batch);
  batch.end();
  if (pe.isComplete())
     pe.reset();
   }
  }