Search in sources :

Example 1 with CircularMovementControl

use of com.almasb.fxgl.entity.control.CircularMovementControl in project FXGL by AlmasB.

the class SmokeSample method initGame.

@Override
protected void initGame() {
    getGameScene().setBackgroundColor(Color.BLACK);
    e = ParticleEmitters.newSmokeEmitter();
    e.setBlendMode(BlendMode.SRC_OVER);
    e.setSize(15, 30);
    e.setNumParticles(10);
    e.setEmissionRate(0.25);
    e.setStartColor(Color.color(0.6, 0.55, 0.5, 0.47));
    e.setEndColor(Color.BLACK);
    e.setExpireFunction((i, x, y) -> Duration.seconds(16));
    e.setVelocityFunction((i, x, y) -> new Point2D(FXGLMath.random() - 0.5, 0));
    e.setAccelerationFunction(() -> new Point2D((FXGLMath.noise1D(7776 + getTick()) - 0.5) * 0.02, 0));
    // e.setSpawnPointFunction((i, x, y) -> new Point2D(x + FXGLMath.noise1D(333 + getTick()) * 150 - 75, y + FXGLMath.noise1D(getTick()) * 150 - 75));
    // Entities.builder()
    // .at(getWidth() / 2, getHeight() - 100)
    // .with(new ParticleControl(e), new RandomMoveControl(2))
    // .buildAndAttach(getGameWorld());
    emitter = ParticleEmitters.newFireEmitter();
    emitter.setSize(5, 15);
    emitter.setVelocityFunction((i, x, y) -> new Point2D(FXGLMath.random() - 0.5, -FXGLMath.random() * 3));
    emitter.setAccelerationFunction(() -> new Point2D(0, 0.05));
    emitter.setExpireFunction((i, x, y) -> Duration.seconds(3));
    emitter.setScaleFunction((i, x, y) -> new Point2D(FXGLMath.random(0, 0.01), FXGLMath.random(-0.05, 0.05)));
    emitter.setStartColor(Color.YELLOW);
    emitter.setEndColor(Color.RED);
    // emitter.setBlendMode(BlendMode.SRC_OVER);
    // emitter.setSourceImage(getAssetLoader().loadTexture("particleTexture2.png").toColor(Color.rgb(230, 75, 40)).getImage());
    entity = Entities.builder().at(getWidth() / 2, getHeight() / 2).with(new ParticleControl(emitter)).buildAndAttach(getGameWorld());
    Entities.builder().at(250, 250).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(new CircularMovementControl(10, 25)).buildAndAttach(getGameWorld());
}
Also used : Point2D(javafx.geometry.Point2D) Rectangle(javafx.scene.shape.Rectangle) ParticleControl(com.almasb.fxgl.effect.ParticleControl) CircularMovementControl(com.almasb.fxgl.entity.control.CircularMovementControl)

Aggregations

ParticleControl (com.almasb.fxgl.effect.ParticleControl)1 CircularMovementControl (com.almasb.fxgl.entity.control.CircularMovementControl)1 Point2D (javafx.geometry.Point2D)1 Rectangle (javafx.scene.shape.Rectangle)1