Search in sources :

Example 86 with Rectangle2D

use of javafx.geometry.Rectangle2D in project Board-Instrumentation-Framework by intel.

the class DynamicTransition method splitImageX.

/**
 * Split the given images into vertical tiles defined by noOfTilesX
 *
 * @param FRONT_IMAGE
 * @param BACK_IMAGE
 */
private void splitImageX(final Image FRONT_IMAGE, final Image BACK_IMAGE) {
    viewPorts.clear();
    for (int i = 0; i < noOfTilesX; i++) {
        // Create the viewports
        viewPorts.add(new Rectangle2D(i * stepSizeX, 0, stepSizeX, FRONT_IMAGE.getHeight()));
        // Update the frontside imageviews
        imageViewsFront.get(i).getTransforms().clear();
        imageViewsFront.get(i).toFront();
        imageViewsFront.get(i).setImage(FRONT_IMAGE);
        imageViewsFront.get(i).setViewport(viewPorts.get(i));
        // Update the backside imageviews
        imageViewsBack.get(i).getTransforms().clear();
        imageViewsBack.get(i).setImage(BACK_IMAGE);
        imageViewsBack.get(i).setViewport(viewPorts.get(i));
    }
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D)

Example 87 with Rectangle2D

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

the class RigidBodyPhysicsSample method spawnHorizontal.

private void spawnHorizontal(double x, double y) {
    var physics = new PhysicsComponent();
    physics.setFixtureDef(new FixtureDef().density(4.5f).friction(1.0f).restitution(0.05f));
    physics.setBodyType(BodyType.DYNAMIC);
    var t = texture("brick.png").subTexture(new Rectangle2D(0, 0, 64, 5));
    entityBuilder().at(x, y).viewWithBBox(t).with(physics).buildAndAttach();
}
Also used : PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) Rectangle2D(javafx.geometry.Rectangle2D) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 88 with Rectangle2D

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

the class ImageToParticlesAnimationSample method initGame.

@Override
protected void initGame() {
    getGameScene().setBackgroundColor(Color.BLACK);
    // based on your image size, you may want to remove the call to .subTexture()
    var texture = texture("robot_stand.png").subTexture(new Rectangle2D(50, 30, 200, 220));
    pixels = ImagesKt.toPixels(texture.getImage()).stream().filter(p -> !p.getColor().equals(Color.TRANSPARENT)).map(p -> {
        var r = new Rectangle(1, 1, p.getColor());
        r.setLayoutX(p.getX());
        r.setLayoutY(p.getY());
        addUINode(r, 250, 150);
        return r;
    }).collect(Collectors.toList());
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Rectangle2D(javafx.geometry.Rectangle2D) CubicCurve(javafx.scene.shape.CubicCurve) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle) Collectors(java.util.stream.Collectors) Duration(javafx.util.Duration) List(java.util.List) Interpolators(com.almasb.fxgl.animation.Interpolators) GameSettings(com.almasb.fxgl.app.GameSettings) Point2D(javafx.geometry.Point2D) ImagesKt(com.almasb.fxgl.texture.ImagesKt) Comparator(java.util.Comparator) GameApplication(com.almasb.fxgl.app.GameApplication) FXGL(com.almasb.fxgl.dsl.FXGL) Rectangle2D(javafx.geometry.Rectangle2D) Rectangle(javafx.scene.shape.Rectangle)

Example 89 with Rectangle2D

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

the class GraphVisSample method makeNode.

private Entity makeNode(int id) {
    var e = entityBuilder().at(FXGLMath.randomPoint(new Rectangle2D(0, 0, getAppWidth(), getAppHeight()))).view(new Circle(NODE_RADIUS, NODE_RADIUS, NODE_RADIUS)).with("id", id).with(new DraggableComponent()).onClick(entity -> {
    // here you can find out more info about the node in question
    }).buildAndAttach();
    nodes.put(id, e);
    return e;
}
Also used : Color(javafx.scene.paint.Color) Rectangle2D(javafx.geometry.Rectangle2D) FXGLMath(com.almasb.fxgl.core.math.FXGLMath) HashMap(java.util.HashMap) Line(javafx.scene.shape.Line) List(java.util.List) Map(java.util.Map) GameSettings(com.almasb.fxgl.app.GameSettings) DraggableComponent(com.almasb.fxgl.dsl.components.DraggableComponent) Circle(javafx.scene.shape.Circle) GameApplication(com.almasb.fxgl.app.GameApplication) Entity(com.almasb.fxgl.entity.Entity) FXGL(com.almasb.fxgl.dsl.FXGL) Circle(javafx.scene.shape.Circle) Rectangle2D(javafx.geometry.Rectangle2D) DraggableComponent(com.almasb.fxgl.dsl.components.DraggableComponent)

Example 90 with Rectangle2D

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

the class UINineSliceSample method initUI.

@Override
protected void initUI() {
    boolean fromSingleImage = true;
    if (fromSingleImage) {
        builder = new NineSliceTextureBuilder(texture("9SliceSprite.jpg")).topLeft(new Rectangle2D(0, 0, 53, 53)).top(new Rectangle2D(53, 0, 420, 53)).topRight(new Rectangle2D(473, 0, 52, 53)).left(new Rectangle2D(0, 52, 53, 420)).center(new Rectangle2D(53, 52, 420, 420)).right(new Rectangle2D(473, 52, 52, 420)).botLeft(new Rectangle2D(0, 473, 53, 52)).botRight(new Rectangle2D(473, 473, 52, 52)).bot(new Rectangle2D(53, 473, 473 - 53, 52));
    } else {
        builder = new NineSliceTextureBuilder(texture("ui_sheet.png")).topLeft(100, 100, 35, 35).topRight(165, 100, 35, 35).botLeft(100, 165, 35, 35).botRight(165, 165, 35, 35).center(135, 135, 30, 30).top(135, 100, 30, 35).bot(135, 165, 30, 35).left(100, 135, 35, 30).right(165, 135, 35, 30);
    }
    TextField fieldW = new TextField();
    fieldW.setText("300");
    fieldW.setPrefWidth(100);
    TextField fieldH = new TextField();
    fieldH.setText("300");
    fieldH.setPrefWidth(100);
    Button generateBtn = new Button("Generate");
    generateBtn.setOnAction(e -> {
        if (texture != null) {
            getGameScene().removeUINode(texture);
            texture.dispose();
        }
        try {
            double w = Double.parseDouble(fieldW.getText());
            double h = Double.parseDouble(fieldH.getText());
            texture = builder.build((int) w, (int) h);
            texture.setTranslateX(100);
            getGameScene().addUINode(texture);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    });
    Button exportBtn = new Button("Export");
    exportBtn.setOnAction(e -> {
        if (texture != null) {
            var fileChooser = createImageSaverDialog();
            var file = fileChooser.showSaveDialog(getGameScene().getRoot().getScene().getWindow());
            if (file != null) {
                saveImageToFile(texture.getImage(), file);
            }
        }
    });
    getGameScene().addUINodes(new VBox(5, fieldW, fieldH, generateBtn, exportBtn));
    generateBtn.fire();
}
Also used : NineSliceTextureBuilder(com.almasb.fxgl.texture.NineSliceTextureBuilder) Button(javafx.scene.control.Button) Rectangle2D(javafx.geometry.Rectangle2D) TextField(javafx.scene.control.TextField) VBox(javafx.scene.layout.VBox) IOException(java.io.IOException)

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