Search in sources :

Example 1 with SelectableComponent

use of com.almasb.fxgl.entity.component.SelectableComponent in project FXGL by AlmasB.

the class SelectedEntitySample method initGame.

@Override
protected void initGame() {
    // 2. create entity and attach to world using fluent API
    Entity e1 = Entities.builder().at(100, 100).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(new SelectableComponent(true)).buildAndAttach();
    Entity e2 = Entities.builder().at(300, 100).viewFromNode(new Rectangle(40, 40, Color.RED)).with(new SelectableComponent(true)).buildAndAttach();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle) SelectableComponent(com.almasb.fxgl.entity.component.SelectableComponent)

Example 2 with SelectableComponent

use of com.almasb.fxgl.entity.component.SelectableComponent in project FXGL by AlmasB.

the class SelectedEntitySample method initGame.

@Override
protected void initGame() {
    player = Entities.builder().type(Type.PLAYER).at(100, 100).viewFromNode(new Rectangle(40, 40)).with(new SelectableComponent(true)).buildAndAttach(getGameWorld());
    enemy = Entities.builder().type(Type.ENEMY).at(200, 100).viewFromNode(new Rectangle(40, 40, Color.RED)).with(new SelectableComponent(true)).buildAndAttach(getGameWorld());
    // 2. click on entity and see it being selected
    getGameWorld().selectedEntityProperty().addListener((o, oldEntity, newEntity) -> {
        System.out.println(oldEntity);
        System.out.println(newEntity);
    });
}
Also used : Rectangle(javafx.scene.shape.Rectangle) SelectableComponent(com.almasb.fxgl.entity.component.SelectableComponent)

Example 3 with SelectableComponent

use of com.almasb.fxgl.entity.component.SelectableComponent 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

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