* @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=Infini
( x = 0, y = 0, width = Infinity, height = Infinity, adapter = undefined, )
| 40 | * @param {PhysicsAdapter} [adapter] - physics adapter to use; defaults to a new {@link BuiltinAdapter} instance |
| 41 | */ |
| 42 | constructor( |
| 43 | x = 0, |
| 44 | y = 0, |
| 45 | width = Infinity, |
| 46 | height = Infinity, |
| 47 | adapter = undefined, |
| 48 | ) { |
| 49 | // call the super constructor |
| 50 | super(x, y, width, height, true); |
| 51 | |
| 52 | // world is the root container |
| 53 | this.name = "rootContainer"; |
| 54 | |
| 55 | // to mimic the previous behavior |
| 56 | this.anchorPoint.set(0, 0); |
| 57 | |
| 58 | /** |
| 59 | * the application (game) this physic world belong to |
| 60 | * @type {Application} |
| 61 | */ |
| 62 | this.app = undefined; |
| 63 | |
| 64 | /** |
| 65 | * Identifier of the active physics adapter, taken from the |
| 66 | * adapter's `physicLabel` field at `Application` construction — |
| 67 | * `"builtin"` (default — `BuiltinAdapter`), `"matter"` |
| 68 | * (`@melonjs/matter-adapter`), or a third-party label. |
| 69 | * The reserved value `"none"` is set when physics is disabled via |
| 70 | * `physic: "none"` in `ApplicationSettings`; `World.step` skips |
| 71 | * the simulation entirely under that label, and the rest of the |
| 72 | * world container behaves like a pure scene graph. |
| 73 | * |
| 74 | * User code can branch on the value without importing the |
| 75 | * adapter class: |
| 76 | * |
| 77 | * ```ts |
| 78 | * if (app.world.physic === "matter") { |
| 79 | * // matter-only setup (constraints, native queries, …) |
| 80 | * } |
| 81 | * ``` |
| 82 | * @see ApplicationSettings.physic |
| 83 | * @see PhysicsAdapter.physicLabel |
| 84 | * @type {string} |
| 85 | * @default "builtin" |
| 86 | * @example |
| 87 | * // disable physics entirely |
| 88 | * app.world.physic = "none"; |
| 89 | */ |
| 90 | this.physic = "builtin"; |
| 91 | |
| 92 | /** |
| 93 | * the rate at which the game world is updated, |
| 94 | * may be greater than or lower than the display fps |
| 95 | * @default 60 |
| 96 | * @see timer.maxfps |
| 97 | */ |
| 98 | this.fps = 60; |
| 99 |