LibGDX particles do not show

906 Views Asked by At

I have a problem with particles in libGDX. Basicly they don't show at all and I have no idea why.

I use Scene2D and I created Particles actor: http://wklej.org/id/1534258/

I create it like this: particleTest = new ParticleEffectActor("test.p");

In my game I have 2 gui stages. I added particles to all of them in show() method of the screen:

menuStage.addActor(particleTest);
gameGuiStage.addActor(particleTest);

I also have another stage for my game (scaled by pixelPerMeter value). I tried to add it like this: effect = new ParticleEffectActor("powerup.p"); gameWorld.getWorldStage().addActor(effect);

In this case I alsotried some tricks with positioning but still no effect.

What is wrong? Thanks for help

1

There are 1 best solutions below

0
On

I finally managed to make a working version:

here's an actor;

package com.apptogo.runner.actors;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

public class ParticleEffectActor extends Image {

    private ParticleEffect effect;

    public ParticleEffectActor(String particleName) {
        super();
        effect = new ParticleEffect();
        effect.load(Gdx.files.internal("gfx/game/particles/" + particleName), Gdx.files.internal("gfx/game/particles"));
        this.setVisible(false);
    }

    @Override
    public void scaleBy(float scaleFactor){
        effect.scaleEffect(scaleFactor);
    }

    @Override
    public void setPosition(float x, float y){
        super.setPosition(x, y);
        effect.setPosition(x, y);
    }

    public void start() {
        effect.start();
    }

    @Override
    public void act(float delta) {
        super.act(delta);
        effect.update(delta);
    }

    @Override
    public void draw(Batch batch, float parentAlpha) {
        super.draw(batch, parentAlpha);
        effect.draw(batch);
    }

    public ParticleEffect getEffect(){ return this.effect; }
}

and this is how I use it:

  effectActor = new ParticleEffectActor("test.p");
    effectActor.scaleBy(1/PPM);
    gameWorld.getWorldStage().addActor(effectActor);

and effectActor.setPosition(getX() + getWidth()/2, getY() + getHeight()/2);

in act()