1

Why doesn't this code work. There are no errors, but nothing is drawn.

The render method contains:

 effect = new ParticleEffect(); effect.setPosition(200, 200); effect.start(); float delta = Gdx.graphics.getDeltaTime(); GL10 gl = Gdx.app.getGraphics().getGL10(); gl.glClear(GL10.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); effect.draw(spriteBatch, delta); spriteBatch.end(); 

4 Answers 4

3

If you are creating a new effect every frame, it will never move or do anything, since it will be reset each frame. You should create the effect outside your loop.

I don't know how the particleeffect will be with no setup. So you should also try adding a texture and set it's preferences.

Sign up to request clarification or add additional context in comments.

1 Comment

I cannot help you unless you write in English.
3

I think only creating constructor for the ParticleEffect does not suffice, so you have to load particle effect file using effect object you have created in the following manner. Also you have to take this thing out of the loop.

effect.load(Gdx.files.internal("data/yellow_particle"), Gdx.files.internal("data"));

Comments

1

Run once:

effect = new ParticleEffect(); effect.load(Gdx.files.internal("path/to/your/particle.p", "directory/with/your/particle/png")); effect.setPosition(200, 200); effect.start(); 

Run in render:

spriteBatch.begin(); effect.draw(spriteBatch, delta); spriteBatch.end(); 

And in dispose:

effect.dispose(); 

Particle.png can be copied from libgdx sources for example: https://github.com/libgdx/libgdx/blob/master/extensions/gdx-tools/assets/particle.png

And watch again the video tutorial - you are messing and missing many things: http://www.youtube.com/watch?v=LCLa-rgR_MA

The tutorial itself covers less things, than video, but pasting here for hope it will be updated: https://github.com/libgdx/libgdx/wiki/2d-particle-effects

Comments

0

Make the particle-effects in your class's constructor. Dont make particle-effects objects every time in your render method. Thats why, your particle effects are initializing every time, and you cant see anything.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.