Search in sources :

Example 1 with EasingInterpolator

use of com.almasb.fxgl.animation.EasingInterpolator in project FXGL by AlmasB.

the class InterpolatorSample method playAnimation.

private void playAnimation(EasingInterpolator interpolator) {
    set("canPlay", false);
    Interpolator ease = getEase(interpolator);
    String animType = ((RadioButton) group2.getSelectedToggle()).getText();
    switch(animType) {
        case "Translate":
            Entities.animationBuilder().interpolator(ease).duration(Duration.seconds(2.3)).onFinished(() -> set("canPlay", true)).translate(player).from(new Point2D(0, -150)).to(new Point2D(0, 300)).buildAndPlay();
            break;
        case "Scale":
            Entities.animationBuilder().interpolator(ease).autoReverse(true).repeat(2).duration(Duration.seconds(1.15)).onFinished(() -> set("canPlay", true)).scale(player).from(new Point2D(1, 1)).to(new Point2D(0, 0)).buildAndPlay();
            break;
        case "Rotate":
            Entities.animationBuilder().interpolator(ease).duration(Duration.seconds(2.3)).onFinished(() -> set("canPlay", true)).rotate(player).rotateFrom(0).rotateTo(360).buildAndPlay();
            break;
    }
}
Also used : Point2D(javafx.geometry.Point2D) EasingInterpolator(com.almasb.fxgl.animation.EasingInterpolator) Interpolator(javafx.animation.Interpolator) RadioButton(javafx.scene.control.RadioButton)

Example 2 with EasingInterpolator

use of com.almasb.fxgl.animation.EasingInterpolator in project FXGL by AlmasB.

the class ParticleSystemSample method initUI.

@Override
protected void initUI() {
    Spinner<Integer> spinnerNumParticles = new Spinner<>(0, 100, 15, 1);
    emitter.numParticlesProperty().bind(spinnerNumParticles.valueProperty());
    Spinner<Double> spinnerRate = new Spinner<>(0.0, 1.0, 1.0, 0.05);
    emitter.emissionRateProperty().bind(spinnerRate.valueProperty());
    Spinner<Double> spinnerMinSize = new Spinner<>(1.0, 100.0, 9.0, 1);
    emitter.minSizeProperty().bind(spinnerMinSize.valueProperty());
    Spinner<Double> spinnerMaxSize = new Spinner<>(1.0, 100.0, 12.0, 1);
    emitter.maxSizeProperty().bind(spinnerMaxSize.valueProperty());
    Spinner<Double> spinnerVelX = new Spinner<>(-500.0, 500.0, 0.0, 10);
    Spinner<Double> spinnerVelY = new Spinner<>(-500.0, 500.0, -30.0, 10);
    spinnerVelX.setPrefWidth(65);
    spinnerVelY.setPrefWidth(65);
    spinnerVelX.valueProperty().addListener((observable, oldValue, newValue) -> {
        emitter.setVelocityFunction((i, x, y) -> new Point2D(newValue, spinnerVelY.getValue()));
    });
    spinnerVelY.valueProperty().addListener((observable, oldValue, newValue) -> {
        emitter.setVelocityFunction((i, x, y) -> new Point2D(spinnerVelX.getValue(), newValue));
    });
    Spinner<Double> spinnerAccelX = new Spinner<>(-150.0, 150.0, 0.0, 10);
    Spinner<Double> spinnerAccelY = new Spinner<>(-150.0, 150.0, 0.0, 10);
    spinnerAccelX.setPrefWidth(65);
    spinnerAccelY.setPrefWidth(65);
    spinnerAccelX.valueProperty().addListener((observable, oldValue, newValue) -> {
        emitter.setAccelerationFunction(() -> new Point2D(newValue, spinnerAccelY.getValue()));
    });
    spinnerAccelY.valueProperty().addListener((observable, oldValue, newValue) -> {
        emitter.setAccelerationFunction(() -> new Point2D(spinnerAccelX.getValue(), newValue));
    });
    ChoiceBox<BlendMode> choiceBlend = getUIFactory().newChoiceBox(FXCollections.observableArrayList(BlendMode.values()));
    emitter.blendModeProperty().bind(choiceBlend.valueProperty());
    choiceBlend.setValue(BlendMode.ADD);
    ChoiceBox<EasingInterpolator> choiceInterpolator = getUIFactory().newChoiceBox(FXCollections.observableArrayList(Interpolators.values()));
    choiceInterpolator.setValue(Interpolators.LINEAR);
    choiceInterpolator.valueProperty().addListener((observable, oldValue, newValue) -> {
        emitter.setInterpolator(newValue.EASE_OUT());
    });
    ColorPicker startColor = new ColorPicker((Color) emitter.getStartColor());
    ColorPicker endColor = new ColorPicker((Color) emitter.getEndColor());
    emitter.startColorProperty().bind(startColor.valueProperty());
    emitter.endColorProperty().bind(endColor.valueProperty());
    VBox vbox = new VBox(10);
    vbox.setTranslateX(700);
    vbox.getChildren().addAll(new HBox(10, new Text("Vel X and Y"), spinnerVelX, spinnerVelY), new HBox(10, new Text("Acc X and Y"), spinnerAccelX, spinnerAccelY), new Text("Number of Particles:"), spinnerNumParticles, new Text("Min Size:"), spinnerMinSize, new Text("Max Size:"), spinnerMaxSize, new Text("Emission Rate:"), spinnerRate, new Text("Start Color:"), startColor, new Text("End Color:"), endColor, choiceBlend, choiceInterpolator);
    getGameScene().addUINode(vbox);
}
Also used : HBox(javafx.scene.layout.HBox) EasingInterpolator(com.almasb.fxgl.animation.EasingInterpolator) ColorPicker(javafx.scene.control.ColorPicker) Spinner(javafx.scene.control.Spinner) BlendMode(javafx.scene.effect.BlendMode) Text(javafx.scene.text.Text) Point2D(javafx.geometry.Point2D) VBox(javafx.scene.layout.VBox)

Example 3 with EasingInterpolator

use of com.almasb.fxgl.animation.EasingInterpolator in project FXGL by AlmasB.

the class InterpolatorSample method initUI.

@Override
protected void initUI() {
    VBox vbox = new VBox(5);
    for (EasingInterpolator interpolator : Interpolators.values()) {
        Button btn = new Button(interpolator.toString());
        btn.disableProperty().bind(getGameState().booleanProperty("canPlay").not());
        btn.setOnAction(e -> playAnimation(interpolator));
        vbox.getChildren().add(btn);
    }
    RadioButton btn1 = new RadioButton("Ease In");
    RadioButton btn2 = new RadioButton("Ease Out");
    RadioButton btn3 = new RadioButton("Ease In Out");
    btn1.setToggleGroup(group);
    btn2.setToggleGroup(group);
    btn3.setToggleGroup(group);
    btn2.setSelected(true);
    RadioButton btn4 = new RadioButton("Translate");
    RadioButton btn5 = new RadioButton("Scale");
    RadioButton btn6 = new RadioButton("Rotate");
    btn4.setToggleGroup(group2);
    btn5.setToggleGroup(group2);
    btn6.setToggleGroup(group2);
    btn4.setSelected(true);
    vbox.getChildren().addAll(btn1, btn2, btn3, btn4, btn5, btn6);
    vbox.setTranslateX(650);
    getGameScene().addUINode(vbox);
}
Also used : EasingInterpolator(com.almasb.fxgl.animation.EasingInterpolator) Button(javafx.scene.control.Button) RadioButton(javafx.scene.control.RadioButton) RadioButton(javafx.scene.control.RadioButton) VBox(javafx.scene.layout.VBox)

Aggregations

EasingInterpolator (com.almasb.fxgl.animation.EasingInterpolator)3 Point2D (javafx.geometry.Point2D)2 RadioButton (javafx.scene.control.RadioButton)2 VBox (javafx.scene.layout.VBox)2 Interpolator (javafx.animation.Interpolator)1 Button (javafx.scene.control.Button)1 ColorPicker (javafx.scene.control.ColorPicker)1 Spinner (javafx.scene.control.Spinner)1 BlendMode (javafx.scene.effect.BlendMode)1 HBox (javafx.scene.layout.HBox)1 Text (javafx.scene.text.Text)1