Search in sources :

Example 1 with Animation

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

the class UIFactory method translate.

default Animation<?> translate(Node node, Point2D from, Point2D to, Duration delay, Duration duration, Runnable onFinishedAction) {
    Animation<?> anim = new Animation<Point2D>(delay, duration, 1, new AnimatedPoint2D(from, to)) {

        @Override
        public void onProgress(Point2D value) {
            node.setTranslateX(value.getX());
            node.setTranslateY(value.getY());
        }
    };
    anim.setOnFinished(onFinishedAction);
    return anim;
}
Also used : AnimatedPoint2D(com.almasb.fxgl.animation.AnimatedPoint2D) AnimatedPoint2D(com.almasb.fxgl.animation.AnimatedPoint2D) Point2D(javafx.geometry.Point2D) Animation(com.almasb.fxgl.animation.Animation)

Example 2 with Animation

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

the class MarioApp method initPhysics.

@Override
protected void initPhysics() {
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.COIN) {

        @Override
        protected void onCollisionBegin(Entity player, Entity coin) {
            coin.getComponent(CollidableComponent.class).setValue(false);
            Animation<?> anim = Entities.animationBuilder().duration(Duration.seconds(0.5)).interpolator(Interpolators.ELASTIC.EASE_IN()).scale(coin).from(new Point2D(1, 1)).to(new Point2D(0, 0)).buildAndPlay();
            anim.setOnFinished(() -> coin.removeFromWorld());
        }
    });
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.DOOR) {

        @Override
        protected void onCollisionBegin(Entity player, Entity door) {
            getDisplay().showMessageBox("Level Complete!", () -> {
                System.out.println("Dialog closed!");
            });
        }
    });
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Point2D(javafx.geometry.Point2D) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler) Animation(com.almasb.fxgl.animation.Animation)

Example 3 with Animation

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

the class UIFactory method scale.

default Animation<?> scale(Node node, Point2D from, Point2D to, Duration delay, Duration duration, Runnable onFinishedAction) {
    Animation<?> anim = new Animation<Point2D>(delay, duration, 1, new AnimatedPoint2D(from, to)) {

        @Override
        public void onProgress(Point2D value) {
            node.setScaleX(value.getX());
            node.setScaleY(value.getY());
        }
    };
    anim.setOnFinished(onFinishedAction);
    return anim;
}
Also used : AnimatedPoint2D(com.almasb.fxgl.animation.AnimatedPoint2D) AnimatedPoint2D(com.almasb.fxgl.animation.AnimatedPoint2D) Point2D(javafx.geometry.Point2D) Animation(com.almasb.fxgl.animation.Animation)

Aggregations

Animation (com.almasb.fxgl.animation.Animation)3 Point2D (javafx.geometry.Point2D)3 AnimatedPoint2D (com.almasb.fxgl.animation.AnimatedPoint2D)2 Entity (com.almasb.fxgl.entity.Entity)1 CollisionHandler (com.almasb.fxgl.physics.CollisionHandler)1