Search in sources :

Example 96 with Rectangle2D

use of javafx.geometry.Rectangle2D in project FXGL by AlmasB.

the class ParticleMorphApp method initGame.

@Override
protected void initGame() {
    pixelIndex = 0;
    getGameScene().setBackgroundColor(Color.BLACK);
    var texture = texture("robot_stand.png").subTexture(new Rectangle2D(50, 30, 200, 220));
    pixels = ImagesKt.toPixels(texture.getImage()).stream().map(p -> {
        var r = new Rectangle(1, 1, p.getColor());
        r.setLayoutX(p.getX());
        r.setLayoutY(p.getY());
        r.setScaleX(3);
        r.setScaleY(3);
        return r;
    }).collect(Collectors.toList());
    pixels.forEach(p -> {
        p.getProperties().put("vel", new Vec2());
        p.getProperties().put("index", pixelIndex++);
        addUINode(p, 250, 150);
    });
    var knight = texture("knight.png", 200, 220);
    pixels2 = ImagesKt.toPixels(knight.getImage()).stream().map(p -> {
        var r = new Rectangle(1, 1, p.getColor());
        r.setLayoutX(p.getX());
        r.setLayoutY(p.getY());
        return r;
    }).collect(Collectors.toList());
    // pixels2.forEach(p -> {
    // addUINode(p, 450, 150);
    // });
    System.out.println(pixels.size() + " " + pixels2.size());
}
Also used : Vec2(com.almasb.fxgl.core.math.Vec2) Rectangle2D(javafx.geometry.Rectangle2D) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

Rectangle2D (javafx.geometry.Rectangle2D)96 Image (javafx.scene.image.Image)14 Point2D (javafx.geometry.Point2D)13 Scene (javafx.scene.Scene)11 Color (javafx.scene.paint.Color)11 Screen (javafx.stage.Screen)11 List (java.util.List)8 IOException (java.io.IOException)7 Rectangle (javafx.scene.shape.Rectangle)7 Stage (javafx.stage.Stage)7 GameApplication (com.almasb.fxgl.app.GameApplication)6 GameSettings (com.almasb.fxgl.app.GameSettings)6 FXGL (com.almasb.fxgl.dsl.FXGL)6 KeyCode (javafx.scene.input.KeyCode)6 Duration (javafx.util.Duration)6 Interpolators (com.almasb.fxgl.animation.Interpolators)4 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)4 Entity (com.almasb.fxgl.entity.Entity)4 BufferedImage (java.awt.image.BufferedImage)4 Collectors (java.util.stream.Collectors)4