use of com.almasb.fxgl.dsl.components.OffscreenCleanComponent in project FXGL by AlmasB.
the class CollisionFilterSample method initGame.
@Override
protected void initGame() {
entityBuilder().type(EType.PLAYER).viewWithBBox(new Rectangle(40, 40, Color.BLUE)).view(new Text("PLAYER")).at(100, 100).with(new CollidableComponent(true), new PhysicsComponent()).buildAndAttach();
entityBuilder().type(EType.ENEMY).viewWithBBox(new Rectangle(40, 40, Color.RED)).view(new Text("ENEMY")).at(400, 100).with(new CollidableComponent(true), new PhysicsComponent()).buildAndAttach();
run(() -> {
CollidableComponent collidable = new CollidableComponent(true);
CollidableComponent collidable2 = new CollidableComponent(true);
if (i == 0) {
debug("No collision with player");
collidable.addIgnoredType(EType.PLAYER);
collidable2.addIgnoredType(EType.PLAYER);
} else if (i == 1) {
debug("No collision with enemy");
collidable.addIgnoredType(EType.ENEMY);
collidable2.addIgnoredType(EType.ENEMY);
} else if (i == 2) {
debug("No collision with player and enemy");
collidable.addIgnoredType(EType.PLAYER);
collidable.addIgnoredType(EType.ENEMY);
collidable2.addIgnoredType(EType.PLAYER);
collidable2.addIgnoredType(EType.ENEMY);
}
i++;
if (i == 3)
i = 0;
// a bullet with no physics
entityBuilder().type(EType.BULLET).viewWithBBox(new Rectangle(20, 10, Color.BLACK)).at(0, 100).with(new ProjectileComponent(new Point2D(1, 0), 100)).with(new OffscreenCleanComponent()).with(collidable).buildAndAttach();
// a bullet with physics
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setOnPhysicsInitialized(() -> physics.setLinearVelocity(100, 0));
entityBuilder().type(EType.BULLET).viewWithBBox(new Rectangle(20, 10, Color.BLACK)).at(0, 130).with(physics).with(new OffscreenCleanComponent()).with(collidable2).buildAndAttach();
}, Duration.seconds(4));
}
Aggregations