use of com.almasb.fxgl.physics.PhysicsWorld in project FXGL by AlmasB.
the class PhysicsSample method initPhysics.
@Override
protected void initPhysics() {
// 3. get physics world and register a collision handler
// between Type.PLAYER and Type.ENEMY
PhysicsWorld physics = getPhysicsWorld();
physics.addCollisionHandler(new CollisionHandler(Type.PLAYER, Type.ENEMY) {
@Override
protected void onHitBoxTrigger(Entity player, Entity enemy, HitBox playerBox, HitBox enemyBox) {
System.out.println(playerBox.getName() + " X " + enemyBox.getName());
}
// the order of entities is determined by
// the order of their types passed into constructor
@Override
protected void onCollisionBegin(Entity player, Entity enemy) {
System.out.println("On Collision Begin");
}
@Override
protected void onCollision(Entity player, Entity enemy) {
System.out.println("On Collision");
}
@Override
protected void onCollisionEnd(Entity player, Entity enemy) {
System.out.println("On Collision End");
}
});
}
use of com.almasb.fxgl.physics.PhysicsWorld in project FXGL by AlmasB.
the class PhysicsCollisionSample method initPhysics.
@Override
protected void initPhysics() {
PhysicsWorld physics = FXGL.getPhysicsWorld();
physics.addCollisionHandler(new CollisionHandler(Type.PLAYER, Type.ENEMY) {
@Override
protected void onHitBoxTrigger(Entity player, Entity enemy, HitBox playerBox, HitBox enemyBox) {
System.out.println(playerBox.getName() + " X " + enemyBox.getName());
}
@Override
protected void onCollisionBegin(Entity player, Entity enemy) {
System.out.println("On Collision Begin");
}
@Override
protected void onCollision(Entity player, Entity enemy) {
System.out.println("On Collision");
}
@Override
protected void onCollisionEnd(Entity player, Entity enemy) {
System.out.println("On Collision End");
}
});
}
use of com.almasb.fxgl.physics.PhysicsWorld in project FXGL by AlmasB.
the class PhysicsSample2 method initPhysics.
@Override
protected void initPhysics() {
// 3. get physics world and register a collision handler
// between Type.PLAYER and Type.ENEMY
PhysicsWorld physics = getPhysicsWorld();
physics.addCollisionHandler(new CollisionHandler(Type.PLAYER, Type.ENEMY) {
@Override
protected void onCollision(Entity player, Entity enemy) {
isColliding = true;
}
});
}
Aggregations