use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.
the class ViewportSample method cinematicViewportBezier.
private void cinematicViewportBezier() {
// 1. get viewport
Viewport viewport = getGameScene().getViewport();
viewport.setX(-getWidth() / 2);
viewport.setY(-getHeight() / 2);
// 2. define "waypoints"
Vec2[] points = { new Vec2(98, 80), new Vec2(1520, 90), new Vec2(1470, 272), new Vec2(171, 293), new Vec2(154, 485), new Vec2(1500, 483), new Vec2(1474, 683), new Vec2(144, 698), new Vec2(161, 892), new Vec2(1475, 888), new Vec2(1477, 1064), new Vec2(108, 1066) };
BezierSpline spline = FXGLMath.closedBezierSpline(points);
Path path = new Path();
path.getElements().add(new MoveTo(98, 80));
for (BezierSpline.BezierCurve c : spline.getCurves()) {
path.getElements().add(new CubicCurveTo(c.getControl1().x, c.getControl1().y, c.getControl2().x, c.getControl2().y, c.getEnd().x, c.getEnd().y));
}
// if open bezier is needed
path.getElements().remove(path.getElements().size() - 1);
Entity camera = Entities.builder().build();
viewport.xProperty().bind(camera.getPositionComponent().xProperty().subtract(getWidth() / 2));
viewport.yProperty().bind(camera.getPositionComponent().yProperty().subtract(getHeight() / 2));
Entities.animationBuilder().duration(Duration.seconds(24)).translate(camera).buildAndPlay();
}
use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.
the class PhysicsControl method reposition.
/**
* Repositions an entity that supports physics directly in the physics world.
* Note: depending on how it is used, it may cause non-physical behavior.
*
* @param point point in game world coordinates (pixels)
*/
public void reposition(Point2D point) {
double w = getEntity().getWidth();
double h = getEntity().getHeight();
Vec2 positionMeters = physicsWorld.toPoint(new Point2D(point.getX() + w / 2, point.getY() + h / 2));
body.setTransform(positionMeters, body.getAngle());
}
use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.
the class PhysicsWorld method createGroundSensor.
private void createGroundSensor(Entity e) {
// 3 is a good ratio of entity width, since we don't want to occupy the full width
// if we want to ban "ledge" jumps
double sensorWidth = e.getWidth() / 3;
double sensorHeight = 5;
// center with respect to entity center
Point2D sensorCenterLocal = new Point2D(0, e.getHeight() / 2 - sensorHeight / 2);
PolygonShape polygonShape = new PolygonShape();
polygonShape.setAsBox(toMetersF(sensorWidth / 2), toMetersF(sensorHeight / 2), new Vec2(toMetersF(sensorCenterLocal.getX()), -toMetersF(sensorCenterLocal.getY())), 0);
// https://github.com/AlmasB/FXGL/issues/491
FixtureDef fd = new FixtureDef().sensor(true).shape(polygonShape);
e.getComponent(PhysicsComponent.class).body.createFixture(fd);
}
use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.
the class SAT method cleanArrays.
private static void cleanArrays() {
for (Vec2 v : axes) freeVec(v);
for (Vec2 v : corners1) freeVec(v);
for (Vec2 v : corners2) freeVec(v);
axes.clear();
corners1.clear();
corners2.clear();
}
use of com.almasb.fxgl.core.math.Vec2 in project FXGL by AlmasB.
the class VarsSample method initGameVars.
@Override
protected void initGameVars(Map<String, Object> vars) {
vars.put("test", -1);
vars.put("vector", new Vec2(1, 1));
vars.put("score", 0);
vars.put("lives", 3);
}
Aggregations