PhysicsManager14 / 15

Physics of a falling ball

Calculate the ball’s position after one step.

Create a world and add a circular body. world.step(1 / 60) simulates one sixtieth of a second. snapshots contains the new coordinates. In a scene, PhysicsSceneService can update the world.

const manager = new PhysicsManager();
const world = manager.createWorld({ worldId: 'demo', config: {} });
world.setBounds({ x: 0, y: 0, width: 540, height: 960 });
const ball = world.addCircleBody({
  bodyId: 'ball', x: 270, y: 100, radius: 20,
});
const snapshots = world.step(1 / 60);
manager.disposeWorld('demo');
BodyA circle with a fixed radius
world.stepCalculate the motion
SpriteShow the ball at its new position