Search in sources :

Example 6 with ExpireCleanComponent

use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.

the class RigidBodyPhysicsSample method spawnBullet.

private void spawnBullet(double x, double y, double vx, double vy) {
    var physics = new PhysicsComponent();
    physics.setFixtureDef(new FixtureDef().density(25.5f).restitution(0.5f));
    physics.setBodyType(BodyType.DYNAMIC);
    physics.setOnPhysicsInitialized(() -> {
        physics.setLinearVelocity(vx * 10, vy * 10);
    });
    entityBuilder().at(x, y).bbox(new HitBox(BoundingShape.circle(450 / 15.0 / 2.0))).view(texture("ball.png", 450 / 15.0, 449 / 15.0)).with(physics).with(new ExpireCleanComponent(Duration.seconds(5)).animateOpacity()).buildAndAttach();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) ExpireCleanComponent(com.almasb.fxgl.dsl.components.ExpireCleanComponent) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 7 with ExpireCleanComponent

use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.

the class RopeJointSample method spawnBullet.

private void spawnBullet(double x, double y, double vx, double vy) {
    var physics = new PhysicsComponent();
    physics.setFixtureDef(new FixtureDef().density(25.5f).restitution(0.5f));
    physics.setBodyType(BodyType.DYNAMIC);
    physics.setOnPhysicsInitialized(() -> {
        physics.setLinearVelocity(vx * 10, vy * 10);
    });
    entityBuilder().at(x, y).bbox(new HitBox(BoundingShape.circle(450 / 15.0 / 2.0))).view(texture("ball.png", 450 / 15.0, 449 / 15.0)).with(physics).with(new ExpireCleanComponent(Duration.seconds(5)).animateOpacity()).buildAndAttach();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) ExpireCleanComponent(com.almasb.fxgl.dsl.components.ExpireCleanComponent) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 8 with ExpireCleanComponent

use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.

the class FiringRangeFactory method newTarget.

@Spawns("target")
public Entity newTarget(SpawnData data) {
    var box = new Box(5, 5, 0.2);
    box.setMaterial(new PhongMaterial(Color.DARKKHAKI));
    var e = entityBuilder(data).type(FiringRangeEntityType.TARGET).bbox(new HitBox(BoundingShape.box3D(5, 5, 0.2))).view(box).collidable().with(new Projectile3DComponent(new Point3D(1, 0, 0), 15)).with(new ExpireCleanComponent(Duration.seconds(6))).build();
    animationBuilder().duration(Duration.seconds(0.6)).interpolator(Interpolators.ELASTIC.EASE_OUT()).scale(e).from(new Point3D(0, 0, 0)).to(new Point3D(1, 1, 1)).buildAndPlay();
    return e;
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) ExpireCleanComponent(com.almasb.fxgl.dsl.components.ExpireCleanComponent) Point3D(javafx.geometry.Point3D) Box(javafx.scene.shape.Box) HitBox(com.almasb.fxgl.physics.HitBox) PhongMaterial(javafx.scene.paint.PhongMaterial) Spawns(com.almasb.fxgl.entity.Spawns)

Aggregations

ExpireCleanComponent (com.almasb.fxgl.dsl.components.ExpireCleanComponent)8 HitBox (com.almasb.fxgl.physics.HitBox)5 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)3 FixtureDef (com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)3 Spawns (com.almasb.fxgl.entity.Spawns)2 ParticleComponent (com.almasb.fxgl.particle.ParticleComponent)2 Point2D (javafx.geometry.Point2D)2 Point3D (javafx.geometry.Point3D)2 PhongMaterial (javafx.scene.paint.PhongMaterial)2 ProjectileComponent (com.almasb.fxgl.dsl.components.ProjectileComponent)1 Entity (com.almasb.fxgl.entity.Entity)1 CacheHint (javafx.scene.CacheHint)1 Box (javafx.scene.shape.Box)1 Sphere (javafx.scene.shape.Sphere)1