Search in sources :

Example 1 with ParticleGroup

use of com.almasb.fxgl.physics.box2d.particle.ParticleGroup in project FXGL by AlmasB.

the class PhysicsWorld method createPhysicsParticles.

private void createPhysicsParticles(Entity e) {
    double x = e.getX();
    double y = e.getY();
    double width = e.getWidth();
    double height = e.getHeight();
    ParticleGroupDef def = e.getComponent(PhysicsParticleComponent.class).getDefinition();
    def.setPosition(toMetersF(x + width / 2), toMetersF(appHeight - (y + height / 2)));
    Shape shape = null;
    BoundingBoxComponent bbox = e.getBoundingBoxComponent();
    if (!bbox.hitBoxesProperty().isEmpty()) {
        if (bbox.hitBoxesProperty().get(0).getShape().type == ShapeType.POLYGON) {
            PolygonShape rectShape = new PolygonShape();
            rectShape.setAsBox(toMetersF(width / 2), toMetersF(height / 2));
            shape = rectShape;
        } else if (bbox.hitBoxesProperty().get(0).getShape().type == ShapeType.CIRCLE) {
            CircleShape circleShape = new CircleShape();
            circleShape.setRadius(toMetersF(width / 2));
            shape = circleShape;
        } else {
            log.warning("Unknown hit box shape: " + bbox.hitBoxesProperty().get(0).getShape().type);
            throw new UnsupportedOperationException();
        }
    }
    if (shape == null) {
        PolygonShape rectShape = new PolygonShape();
        rectShape.setAsBox(toMetersF(width / 2), toMetersF(height / 2));
        shape = rectShape;
    }
    def.setShape(shape);
    ParticleGroup particleGroup = jboxWorld.createParticleGroup(def);
    Color color = e.getComponent(PhysicsParticleComponent.class).getColor();
    e.addControl(new PhysicsParticleControl(particleGroup, color, this));
}
Also used : ParticleGroupDef(com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef) BoundingBoxComponent(com.almasb.fxgl.entity.component.BoundingBoxComponent) ParticleGroup(com.almasb.fxgl.physics.box2d.particle.ParticleGroup) Color(javafx.scene.paint.Color)

Aggregations

BoundingBoxComponent (com.almasb.fxgl.entity.component.BoundingBoxComponent)1 ParticleGroup (com.almasb.fxgl.physics.box2d.particle.ParticleGroup)1 ParticleGroupDef (com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef)1 Color (javafx.scene.paint.Color)1