Search in sources :

Example 1 with ParticleEmitter

use of com.almasb.fxgl.effect.ParticleEmitter in project FXGL by AlmasB.

the class ParticlesSample method initInput.

@Override
protected void initInput() {
    Input input = getInput();
    input.addAction(new UserAction("Spawn Explosion") {

        @Override
        protected void onActionBegin() {
            // 1. create entity
            Entity explosion = new Entity();
            explosion.setPosition(input.getMousePositionWorld());
            // 2. create and configure emitter + control
            ParticleEmitter emitter = ParticleEmitters.newExplosionEmitter(400);
            ParticleControl control = new ParticleControl(emitter);
            // we also want the entity to destroy itself when particle control is done
            control.setOnFinished(explosion::removeFromWorld);
            // 3. add control to entity
            explosion.addControl(control);
            // 4. add entity to game world
            getGameWorld().addEntity(explosion);
        }
    }, MouseButton.PRIMARY);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) ParticleEmitter(com.almasb.fxgl.effect.ParticleEmitter) Entity(com.almasb.fxgl.entity.Entity) Input(com.almasb.fxgl.input.Input) ParticleControl(com.almasb.fxgl.effect.ParticleControl)

Example 2 with ParticleEmitter

use of com.almasb.fxgl.effect.ParticleEmitter in project FXGL by AlmasB.

the class RainSample method initGame.

@Override
protected void initGame() {
    Entities.builder().viewFromTexture("underwater3.png").buildAndAttach(getGameWorld());
    // example - multiply color with existing
    ParticleEmitter emitter = ParticleEmitters.newRainEmitter((int) getWidth() / 2);
    emitter.setSourceImage(getAssetLoader().loadTexture("rain.png").multiplyColor(Color.RED).getImage());
    Entities.builder().with(new ParticleControl(emitter)).buildAndAttach(getGameWorld());
    // example - set color
    ParticleEmitter emitter2 = ParticleEmitters.newRainEmitter((int) getWidth() / 2);
    emitter2.setSourceImage(getAssetLoader().loadTexture("rain.png").toColor(Color.RED).getImage());
    emitter2.setInterpolator(Interpolators.EXPONENTIAL.EASE_OUT());
    Entities.builder().at(getWidth() / 2, 0).with(new ParticleControl(emitter2)).buildAndAttach(getGameWorld());
}
Also used : ParticleEmitter(com.almasb.fxgl.effect.ParticleEmitter) ParticleControl(com.almasb.fxgl.effect.ParticleControl)

Example 3 with ParticleEmitter

use of com.almasb.fxgl.effect.ParticleEmitter in project FXGL by AlmasB.

the class ScifiSample method addRain.

private void addRain() {
    ParticleEmitter emitter = ParticleEmitters.newRainEmitter(getWidth());
    emitter.setSourceImage(getAssetLoader().loadTexture("rain.png").multiplyColor(Color.LIGHTBLUE).getImage());
    Entity rain = Entities.builder().with(new ParticleControl(emitter)).buildAndAttach(getGameWorld());
    rain.getPositionComponent().xProperty().bind(getGameScene().getViewport().xProperty());
    rain.getPositionComponent().yProperty().bind(getGameScene().getViewport().yProperty());
}
Also used : ParticleEmitter(com.almasb.fxgl.effect.ParticleEmitter) Entity(com.almasb.fxgl.entity.Entity) ParticleControl(com.almasb.fxgl.effect.ParticleControl)

Aggregations

ParticleControl (com.almasb.fxgl.effect.ParticleControl)3 ParticleEmitter (com.almasb.fxgl.effect.ParticleEmitter)3 Entity (com.almasb.fxgl.entity.Entity)2 Input (com.almasb.fxgl.input.Input)1 UserAction (com.almasb.fxgl.input.UserAction)1