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();
}
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);
});
}
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);
});
}
Aggregations