Skip to main content

WorldBoundary2DBehavior

@zylem/game-lib


@zylem/game-lib / behavior / WorldBoundary2DBehavior

Variable: WorldBoundary2DBehavior

const WorldBoundary2DBehavior: BehaviorDescriptor<WorldBoundary2DOptions, WorldBoundary2DHandle, unknown>

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/world-boundary-2d.d.ts:140

WorldBoundary2DBehavior

Example​

import { WorldBoundary2DBehavior } from "@zylem/game-lib/behavior";

const ship = createSprite({ ... });
const boundary = ship.use(WorldBoundary2DBehavior, {
boundaries: { left: -10, right: 10, bottom: -7.5, top: 7.5 },
});

ship.onUpdate(({ me }) => {
let moveX = ..., moveY = ...;
const hits = boundary.getLastHits(); // Fully typed!
({ moveX, moveY } = boundary.getMovement(moveX, moveY));
me.moveXY(moveX, moveY);
});