Reputation: 99
I'm trying to use a particle effect, but I encounter an error associated with this task before my application starts.
This is how I've set it up:
private ParticleEffect particle;
@Override
public void create(){...
ParticleEffect particle = new ParticleEffect();
particle.load(Gdx.files.internal("data/effects/flame1"), Gdx.files.internal("data/effects"));
particle.setPosition(Gdx.graphics.getWidth() /2, Gdx.graphics.getHeight() /2);
particle.start();
.........}
@Override
public void render(){...
spriteBatch.begin();
particle.draw(spriteBatch, Gdx.graphics.getDeltaTime());
spriteBatch.end();
Note that my particle effects file and corresponding source image file is located under data/effects folder. I do note that my particle effects file that I saved from the particle effects editor does not seem to be a .p file type. Instead, it seems to be of type 'file' only. Perhaps this is a possible cause of the error?
ERROR:
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.name.appname.GameClass.render(GameClass.java:111)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:207)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
java:111 is:
particle.draw(spriteBatch, Gdx.graphics.getDeltaTime());
I followed this tutorial: http://www.youtube.com/watch?v=LCLa-rgR_MA
Upvotes: 2
Views: 486
Reputation: 19776
Have a look at this again:
private ParticleEffect particle;
@Override
public void create(){...
ParticleEffect particle = new ParticleEffect();
This is called shadowing. You accidentally create a new local variable of the same type and with the same name and instantiate that instead of the field of your class.
Change it to that:
private ParticleEffect particle;
@Override
public void create(){...
particle = new ParticleEffect();
Upvotes: 5