use of com.almasb.fxgl.effect.ParticleControl 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());
}
use of com.almasb.fxgl.effect.ParticleControl in project FXGL by AlmasB.
the class ParticleSystemSample method initGame.
@Override
protected void initGame() {
Entities.builder().viewFromNode(new Rectangle(getWidth() - 300, getHeight())).buildAndAttach();
emitter = ParticleEmitters.newFireEmitter();
particleEntity = Entities.builder().at((getWidth() - 300) / 2, getHeight() / 2).with(new ParticleControl(emitter)).buildAndAttach();
}
use of com.almasb.fxgl.effect.ParticleControl in project FXGL by AlmasB.
the class ParticleTextureSample method initGame.
@Override
protected void initGame() {
Entities.builder().viewFromNode(new Rectangle(getWidth(), getHeight())).buildAndAttach(getGameWorld());
emitter = ParticleEmitters.newExplosionEmitter(100);
emitter.setSize(5, 20);
emitter.setNumParticles(24);
emitter.setMaxEmissions(Integer.MAX_VALUE);
emitter.setEmissionRate(0.1);
emitter.setExpireFunction((i, x, y) -> Duration.seconds(FXGLMath.random(2, 2)));
emitter.setVelocityFunction((i, x, y) -> Vec2.fromAngle(360 / 24 * i).toPoint2D().multiply(100));
emitter.setAccelerationFunction(() -> new Point2D(0, 30));
emitter.setSourceImage(getAssetLoader().loadTexture("particleTexture2.png").multiplyColor(Color.rgb(230, 75, 40)).getImage());
emitter.setInterpolator(Interpolators.EXPONENTIAL.EASE_OUT());
entity = Entities.builder().at(getWidth() / 2, getHeight() / 2).with(new ParticleControl(emitter)).buildAndAttach();
// Entities.builder()
// .at(520, 180)
// .viewFromNode(new Circle(5, Color.WHITE))
// .buildAndAttach();
//
// Entities.builder()
// .at(520, 252)
// .viewFromNode(new Circle(5, Color.WHITE))
// .buildAndAttach();
}
use of com.almasb.fxgl.effect.ParticleControl 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);
}
use of com.almasb.fxgl.effect.ParticleControl 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());
}
Aggregations