const renderLayers = {
foreground: 1 << 0,
};
const gravity = new Vector2(0, -600);
export const createWreckingBallGame = async (): Promise<Game> => {
const { game, world, renderContext, time } = createGame('demo-game');
createCamera(world, {
isStatic: true,
cullingMask: renderLayers.foreground,
verticalWorldUnits: DEMO_VERTICAL_WORLD_UNITS,
});
const physicsWorld = new PhysicsWorld({ gravity });
await createWreckingBall(world, renderContext, renderLayers.foreground);
// `createRevoluteJointEcsSystem` must run before
// `createPhysicsSyncEcsSystem`, which is what steps `physicsWorld`:
// newly-added joints need to be registered before that step happens (see
// the Revolute Joints guide's registration-order caution).
// `createArmEcsSystem` only needs to run before `createRenderEcsSystem`,
// so its updated arm is reflected in this tick's render.
world.addSystem(createRevoluteJointEcsSystem(physicsWorld));
world.addSystem(createArmEcsSystem());
world.addSystem(createCameraEcsSystem(time));
world.addSystem(createRenderEcsSystem(renderContext));
world.addSystem(createPhysicsSyncEcsSystem(physicsWorld, time));
return game;
};
A ball is hinged to a crane by a long arm, pulled back to one side, and released exactly once, when the scene is built, swinging into a wall of bricks. The joint only keeps the ball swinging about the crane's pivot; knocking the wall down comes entirely from the engine's ordinary collision resolution between the ball and the bricks, the same combination of joint and collisions used in the Newton's Cradle demo. After the first swing it's left alone rather than re-launched, so it settles the way a real wrecking ball would after a single push.