Search in sources :

Example 1 with ColoredTexture

use of com.almasb.fxgl.texture.ColoredTexture in project FXGL by AlmasB.

the class RemoveSelectedEntitesBug method initGame.

@Override
protected void initGame() {
    Entity e1 = Entities.builder().at(100, 100).viewFromNode(new ColoredTexture(40, 30, Color.BLUE)).with(new SelectableComponent(true)).buildAndAttach(getGameWorld());
    Entity e2 = Entities.builder().at(200, 100).viewFromNode(new Rectangle(40, 40, Color.RED)).with(new SelectableComponent(true)).buildAndAttach(getGameWorld());
    Cursor cursor = getGameScene().getRoot().getCursor();
    // this solves the issue, I think when mouse is clicked / released the game cursor is overridden
    // e1.getView().setCursor(cursor);
    // e2.getView().setCursor(cursor);
    getGameWorld().selectedEntityProperty().addListener((o, oldEntity, newEntity) -> {
        if (newEntity != null)
            getGameWorld().removeEntity(newEntity);
    });
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle) Cursor(javafx.scene.Cursor) ColoredTexture(com.almasb.fxgl.texture.ColoredTexture) SelectableComponent(com.almasb.fxgl.entity.component.SelectableComponent)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)1 SelectableComponent (com.almasb.fxgl.entity.component.SelectableComponent)1 ColoredTexture (com.almasb.fxgl.texture.ColoredTexture)1 Cursor (javafx.scene.Cursor)1 Rectangle (javafx.scene.shape.Rectangle)1