use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class SaveSample method initGame.
private void initGame(Point2D playerPos, Point2D enemyPos) {
playerPosition = playerPos;
enemyPosition = enemyPos;
player = new Entity();
player.getTypeComponent().setValue(Type.PLAYER);
player.getPositionComponent().setValue(playerPosition);
player.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.BLUE)));
playerControl = new PlayerControl();
player.addControl(playerControl);
enemy = new Entity();
enemy.getTypeComponent().setValue(Type.ENEMY);
enemy.getPositionComponent().setValue(enemyPosition);
enemy.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.RED)));
getGameWorld().addEntities(player, enemy);
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class GameScene method destroyView.
private void destroyView(ViewComponent viewComponent) {
EntityView view = viewComponent.getView();
removeGameView(view, viewComponent.getRenderLayer());
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class GameScene method initView.
private void initView(ViewComponent viewComponent) {
EntityView view = viewComponent.getView();
addGameView(view, viewComponent.getRenderLayer());
viewComponent.renderLayerProperty().addListener((o, oldLayer, newLayer) -> {
getRenderGroup(oldLayer).getChildren().remove(view);
getRenderGroup(newLayer).getChildren().add(view);
});
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class RangeTest method onUpdate.
@Override
protected void onUpdate(double tpf) {
List<Entity> list = getGameWorld().getEntitiesInRange(player.getBoundingBoxComponent().range(40, 40));
list.forEach(e -> {
if (e == markers)
return;
EntityView view = e.getComponent(ViewComponent.class).getView();
view.getNodes().stream().map(n -> (Rectangle) n).forEach(r -> r.setFill(Color.YELLOW));
});
List<Entity> list2 = getGameWorld().getEntitiesCopy();
list2.removeAll(list);
list2.forEach(e -> {
EntityView view = e.getComponent(ViewComponent.class).getView();
view.getNodes().stream().map(n -> (Rectangle) n).forEach(r -> r.setFill(Color.BLACK));
});
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class RangeTest method initGame.
@Override
protected void initGame() {
spawnEntity(100, 100);
spawnEntity(500, 300);
spawnEntity(300, 15);
spawnEntity(400, 500);
spawnEntity(500, 500);
player = new Entity();
player.getPositionComponent().setValue(400, 300);
player.getViewComponent().setView(new EntityView(new Rectangle(40, 40)), true);
playerControl = new PlayerControl();
player.addControl(playerControl);
markers = new Entity();
EntityView view = new EntityView();
view.addNode(getMarker(-40, 0));
view.addNode(getMarker(40, 0));
view.addNode(getMarker(0, -40));
view.addNode(getMarker(0, 40));
view.addNode(getMarker(-40, -40));
view.addNode(getMarker(40, -40));
view.addNode(getMarker(-40, 40));
view.addNode(getMarker(40, 40));
markers.getViewComponent().setView(view);
markers.getPositionComponent().xProperty().bind(player.getPositionComponent().xProperty());
markers.getPositionComponent().yProperty().bind(player.getPositionComponent().yProperty());
getGameWorld().addEntities(player, markers);
}
Aggregations