Search in sources :

Example 1 with DrawableComponent

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

the class DrawableSample method initGame.

@Override
protected void initGame() {
    BiConsumer<GraphicsContext, Entity> drawing = (g, entity) -> {
        Point2D pos = entity.getPosition();
        g.setFill(Color.BLUE);
        g.fillRect(pos.getX(), pos.getY(), 40, 40);
    };
    Entity entity = new Entity();
    entity.setPosition(400, 300);
    entity.addComponent(new DrawableComponent(drawing));
    Entity entity2 = new Entity();
    entity2.setPosition(750, 300);
    entity2.addComponent(new DrawableComponent(drawing));
    getGameWorld().addEntities(entity, entity2);
}
Also used : Color(javafx.scene.paint.Color) DrawableComponent(com.almasb.fxgl.entity.component.DrawableComponent) GraphicsContext(javafx.scene.canvas.GraphicsContext) BiConsumer(java.util.function.BiConsumer) Point2D(javafx.geometry.Point2D) GameSettings(com.almasb.fxgl.settings.GameSettings) GameApplication(com.almasb.fxgl.app.GameApplication) Entity(com.almasb.fxgl.entity.Entity) Entity(com.almasb.fxgl.entity.Entity) DrawableComponent(com.almasb.fxgl.entity.component.DrawableComponent) GraphicsContext(javafx.scene.canvas.GraphicsContext) Point2D(javafx.geometry.Point2D)

Aggregations

GameApplication (com.almasb.fxgl.app.GameApplication)1 Entity (com.almasb.fxgl.entity.Entity)1 DrawableComponent (com.almasb.fxgl.entity.component.DrawableComponent)1 GameSettings (com.almasb.fxgl.settings.GameSettings)1 BiConsumer (java.util.function.BiConsumer)1 Point2D (javafx.geometry.Point2D)1 GraphicsContext (javafx.scene.canvas.GraphicsContext)1 Color (javafx.scene.paint.Color)1