/** * an object representing the physic world, and responsible for managing and updating all children and physics * @category Container */ export default class World extends Container { /** * @param {number} [x=0] - position of the container (accessible via the inherited pos.x property) * @param {number} [y=0] - position of the container (accessible via the inherited pos.y property) * @param {number} [width=Infinity] - width of the world container * @param {number} [height=Infinity] - height of the world container * @param {PhysicsAdapter} [adapter] - physics adapter to use; defaults to a new {@link BuiltinAdapter} instance */ constructor(x?: number, y?: number, width?: number, height?: number, adapter?: PhysicsAdapter); /** * the application (game) this physic world belong to * @type {Application} */ app: Application; /** * Identifier of the active physics adapter, taken from the * adapter's `physicLabel` field at `Application` construction — * `"builtin"` (default — `BuiltinAdapter`), `"matter"` * (`@melonjs/matter-adapter`), or a third-party label. * The reserved value `"none"` is set when physics is disabled via * `physic: "none"` in `ApplicationSettings`; `World.step` skips * the simulation entirely under that label, and the rest of the * world container behaves like a pure scene graph. * * User code can branch on the value without importing the * adapter class: * * ```ts * if (app.world.physic === "matter") { * // matter-only setup (constraints, native queries, …) * } * ``` * @see ApplicationSettings.physic * @see PhysicsAdapter.physicLabel * @type {string} * @default "builtin" * @example * // disable physics entirely * app.world.physic = "none"; */ physic: string; /** * the rate at which the game world is updated, * may be greater than or lower than the display fps * @default 60 * @see timer.maxfps */ fps: number; /** * Enabled pre-rendering for all tile layers.
* If false layers are rendered dynamically, if true layers are first fully rendered into an offscreen canvas.
* the "best" rendering method depends of your game (amount of layer, layer size, amount of tiles per layer, etc.)
* Note : rendering method is also configurable per layer by adding a boolean "preRender" property to your layer in Tiled ({@link https://doc.mapeditor.org/en/stable/manual/custom-properties/#adding-properties}). * @type {boolean} * @default false */ preRender: boolean; /** * Enable the WebGL2 procedural shader path for orthogonal tile * layers. When `true` (default), eligible layers render via a * single quad per tileset + a fragment shader doing per-pixel GID * lookup — bypassing the per-tile drawImage loop entirely. * Supported features on the shader path: animated tiles, all * three flip bits (H/V/AD), per-layer opacity/tint/blend mode, * and oversized bottom-aligned tiles up to 4 cells of overflow. * Layers that don't qualify (Canvas/WebGL1, non-orthogonal, * collection-of-image tilesets, non-zero `tileoffset`, or tile * overflow beyond the shader's 4-cell limit) fall back to the * legacy path automatically. Set to `false` to disable globally. * @type {boolean} * @default true */ gpuTilemap: boolean; /** * the physics adapter driving this world. Defaults to a * {@link BuiltinAdapter} wrapping the engine's native SAT-based * physics. Override at `Application` construction time via * `settings.physic.adapter`. Cannot be swapped at runtime. * @type {PhysicsAdapter} */ adapter: PhysicsAdapter; /** * Spatial broadphase used by built-in physics and pointer * event picking. The concrete class depends on * {@link Container#sortOn}: under `"depth"` (the value * `Camera3d.defaultSortOn` sets on stage reset) it's an * `Octree`; under any 2D sortOn it's a `QuadTree`. The choice * is reactive — the `sortOn` setter swaps the broadphase if a * 2D↔3D boundary crossing occurs, so stage transitions between * Camera2d and Camera3d stages are handled transparently. * * Implementation detail — game code shouldn't reach in here. * Use `world.adapter.queryAABB(rect)` / * `world.adapter.querySphere(sphere)` / * `world.adapter.raycast(...)` instead. * @type {import("./broadphase/broadphase.ts").Broadphase} */ broadphase: import("./broadphase/broadphase.ts").Broadphase; /** * Active physics bodies in this simulation. Backed by the active * adapter; mutating this set directly is no longer the recommended * pattern — use `world.adapter.addBody(...)` / `removeBody(...)`. * * Adapters that don't expose a native `bodies` Set (e.g. third-party * integrations that own their own body storage) cause this getter * to return a frozen empty Set, so any `world.bodies.add(...)` * attempt throws `TypeError` instead of silently mutating a * throwaway. * @returns {Set} */ get bodies(): Set; set gravity(v: Vector2d); /** * world gravity. Mutate to change at runtime. * @returns {Vector2d} */ get gravity(): Vector2d; /** * the collision detector instance used by this world instance. * Available only when the active adapter is {@link BuiltinAdapter}. * @returns {Detector | undefined} */ get detector(): Detector | undefined; /** * Add a physic body to the game world. Legacy API for code that * constructed `new Body(...)` directly and now wants to register it * with the active physics adapter. * @see Container.addChild * @param {Body} body * @returns {World} this game world */ addBody(body: Body): World; /** * Remove a physic body from the game world * @see Container.removeChild * @param {Body} body * @returns {World} this game world */ removeBody(body: Body): World; /** * Apply gravity to the given body. Backward-compat shim; the actual * simulation runs through the active adapter. * @private * @param {Body} body */ private bodyApplyGravity; /** * update the physics simulation by one step (called by the game world update method) * @param {number} dt - the time passed since the last frame update */ step(dt: number): void; } import Container from "../renderable/container.js"; import type Application from "./../application/application.ts"; import type { PhysicsAdapter } from "./adapter.ts"; import type Body from "./builtin/body.js"; import type { Vector2d } from "../math/vector2d.ts"; import type Detector from "./builtin/detector.js"; //# sourceMappingURL=world.d.ts.map