Search in sources :

Example 6 with ParticleControl

use of com.almasb.fxgl.effect.ParticleControl 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)

Example 7 with ParticleControl

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

the class GameScene method onUpdate.

public void onUpdate(double tpf) {
    getViewport().onUpdate(tpf);
    boolean dirty = drawables.isNotEmpty() || particles.isNotEmpty();
    if (dirty || wasDirty) {
        particlesGC.setGlobalAlpha(1);
        particlesGC.setGlobalBlendMode(BlendMode.SRC_OVER);
        // https://github.com/AlmasB/FXGL/issues/494
        particlesGC.clearRect(0, 0, getWidth(), getHeight());
        wasDirty = false;
    }
    for (Entity e : drawables) {
        e.getComponentOptional(DrawableComponent.class).ifPresent(d -> d.draw(particlesGC));
    }
    for (ParticleControl particle : particles) {
        particle.renderParticles(particlesGC, getViewport().getOrigin());
    }
    wasDirty = dirty;
}
Also used : DrawableComponent(com.almasb.fxgl.entity.component.DrawableComponent) PhysicsParticleControl(com.almasb.fxgl.physics.PhysicsParticleControl) ParticleControl(com.almasb.fxgl.effect.ParticleControl)

Aggregations

ParticleControl (com.almasb.fxgl.effect.ParticleControl)7 ParticleEmitter (com.almasb.fxgl.effect.ParticleEmitter)3 Rectangle (javafx.scene.shape.Rectangle)3 Entity (com.almasb.fxgl.entity.Entity)2 Point2D (javafx.geometry.Point2D)2 DrawableComponent (com.almasb.fxgl.entity.component.DrawableComponent)1 CircularMovementControl (com.almasb.fxgl.entity.control.CircularMovementControl)1 Input (com.almasb.fxgl.input.Input)1 UserAction (com.almasb.fxgl.input.UserAction)1 PhysicsParticleControl (com.almasb.fxgl.physics.PhysicsParticleControl)1