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);
}
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());
}
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());
}
Aggregations