远方有多远,请你告诉我!

libGDX加载2D粒子

Posted on By 赵赵赵小白

/**
 * @author Zzzxb  2019/8/29 22:05
 * @description:
 */
public class Welcome extends ApplicationAdapter {
    private SpriteBatch batch;
    private float x = 100f, y = 100f;
    private float speed = 5f;
    ParticleEffect particleEffect;

    public Welcome() {
        batch = new SpriteBatch();
        particleEffect = new ParticleEffect();
        particleEffect.load(Gdx.files.internal("a.p"), Gdx.files.internal(""));
        particleEffect.setPosition(x+25,y+25);
        particleEffect.start();
    }

    @Override
    public void render() {
        batch.begin();
        particleEffect.setPosition(x+25,y+25);
        particleEffect.draw(batch, Gdx.graphics.getDeltaTime());
        update();
        batch.end();
    }

    public void update() {
        if (Gdx.input.isKeyPressed(Input.Keys.J)) {
            y -= speed;
        }
        if (Gdx.input.isKeyPressed(Input.Keys.K)) {
            y += speed;
        }
        if (Gdx.input.isKeyPressed(Input.Keys.H)) {
            x -= speed;
        }
        if (Gdx.input.isKeyPressed(Input.Keys.L)) {
            x += speed;
        }
    }

    @Override
    public void dispose() {
        texture.dispose();
        batch.dispose();
    }
}

load2dGranule