melonjs 19.4.0 → 19.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/build/application/application.d.ts.map +1 -1
- package/build/application/settings.d.ts +25 -2
- package/build/application/settings.d.ts.map +1 -1
- package/build/audio/audio.d.ts +77 -253
- package/build/audio/audio.d.ts.map +1 -1
- package/build/audio/backend.d.ts +121 -0
- package/build/audio/backend.d.ts.map +1 -0
- package/build/audio/playback.d.ts +157 -0
- package/build/audio/playback.d.ts.map +1 -0
- package/build/audio/procedural.d.ts +105 -0
- package/build/audio/procedural.d.ts.map +1 -0
- package/build/audio/types.d.ts +205 -0
- package/build/audio/types.d.ts.map +1 -0
- package/build/index.d.ts +6 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2447 -396
- package/build/index.js.map +4 -4
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/level/tiled/TMXTileset.d.ts +12 -0
- package/build/level/tiled/TMXTileset.d.ts.map +1 -1
- package/build/level/tiled/factories/shape.d.ts +1 -1
- package/build/level/tiled/factories/shape.d.ts.map +1 -1
- package/build/level/tiled/factories/tile.d.ts.map +1 -1
- package/build/loader/loader.d.ts +2 -2
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/parsers/aseprite.d.ts +37 -0
- package/build/loader/parsers/aseprite.d.ts.map +1 -0
- package/build/physics/adapter.d.ts +560 -0
- package/build/physics/adapter.d.ts.map +1 -0
- package/build/physics/bounds.d.ts +18 -5
- package/build/physics/bounds.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +605 -0
- package/build/physics/builtin/body.d.ts.map +1 -0
- package/build/physics/builtin/builtin-adapter.d.ts +91 -0
- package/build/physics/builtin/builtin-adapter.d.ts.map +1 -0
- package/build/physics/builtin/detector.d.ts +167 -0
- package/build/physics/builtin/detector.d.ts.map +1 -0
- package/build/physics/builtin/quadtree.d.ts +112 -0
- package/build/physics/builtin/quadtree.d.ts.map +1 -0
- package/build/physics/builtin/raycast.d.ts +4 -0
- package/build/physics/builtin/raycast.d.ts.map +1 -0
- package/build/physics/{sat.d.ts → builtin/sat.d.ts} +7 -7
- package/build/physics/builtin/sat.d.ts.map +1 -0
- package/build/physics/world.d.ts +61 -26
- package/build/physics/world.d.ts.map +1 -1
- package/build/renderable/collectable.d.ts +7 -1
- package/build/renderable/collectable.d.ts.map +1 -1
- package/build/renderable/container.d.ts +0 -13
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +78 -17
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/trigger.d.ts +14 -1
- package/build/renderable/trigger.d.ts.map +1 -1
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
- package/build/system/timer.d.ts +0 -5
- package/build/system/timer.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +0 -130
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/renderer.d.ts +111 -0
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -1
- package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
- package/build/video/webgl/effects/shine.d.ts +87 -0
- package/build/video/webgl/effects/shine.d.ts.map +1 -0
- package/build/video/webgl/glshader.d.ts +46 -16
- package/build/video/webgl/glshader.d.ts.map +1 -1
- package/build/video/webgl/shadereffect.d.ts +23 -4
- package/build/video/webgl/shadereffect.d.ts.map +1 -1
- package/build/video/webgl/utils/uniforms.d.ts +8 -0
- package/build/video/webgl/utils/uniforms.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +0 -106
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/build/physics/body.d.ts +0 -351
- package/build/physics/body.d.ts.map +0 -1
- package/build/physics/detector.d.ts +0 -72
- package/build/physics/detector.d.ts.map +0 -1
- package/build/physics/quadtree.d.ts +0 -69
- package/build/physics/quadtree.d.ts.map +0 -1
- package/build/physics/sat.d.ts.map +0 -1
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import Entity from "../../renderable/entity/entity.js";
|
|
3
|
+
* @import Container from "../../renderable/container.js";
|
|
4
|
+
* @import Renderable from "../../renderable/renderable.js";
|
|
5
|
+
* @import Sprite from "../../renderable/sprite.js";
|
|
6
|
+
* @import NineSliceSprite from "../../renderable/nineslicesprite.js";
|
|
7
|
+
* @import {Vector2d} from "../../math/vector2d.js";
|
|
8
|
+
* @import ResponseObject from "../response.js";
|
|
9
|
+
**/
|
|
10
|
+
/**
|
|
11
|
+
* a Generic Physic Body Object with some physic properties and behavior functionality, to add as a member of a Renderable.
|
|
12
|
+
* @category Physics
|
|
13
|
+
* @see Renderable.body
|
|
14
|
+
*/
|
|
15
|
+
export default class Body {
|
|
16
|
+
/**
|
|
17
|
+
* @param {Renderable|Container|Entity|Sprite|NineSliceSprite} ancestor - the parent object this body is attached to
|
|
18
|
+
* @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Point|Point[]|Bounds|Bounds[]|object} [shapes] - a initial shape, list of shapes, or JSON object defining the body
|
|
19
|
+
* @param {Function} [onBodyUpdate] - callback for when the body is updated (e.g. add/remove shapes)
|
|
20
|
+
*/
|
|
21
|
+
constructor(ancestor: Renderable | Container | Entity | Sprite | NineSliceSprite, shapes?: Rect | Rect[] | Polygon | Polygon[] | Line | Line[] | Ellipse | Ellipse[] | Point | Point[] | Bounds | Bounds[] | object, onBodyUpdate?: Function);
|
|
22
|
+
/**
|
|
23
|
+
* a reference to the parent object that contains this body,
|
|
24
|
+
* or undefined if it has not been added to one.
|
|
25
|
+
* @public
|
|
26
|
+
* @type {Renderable|Container|Entity|Sprite|NineSliceSprite}
|
|
27
|
+
* @default undefined
|
|
28
|
+
*/
|
|
29
|
+
public ancestor: Renderable | Container | Entity | Sprite | NineSliceSprite;
|
|
30
|
+
/**
|
|
31
|
+
* The AABB bounds box representing this body
|
|
32
|
+
* @public
|
|
33
|
+
* @type {Bounds}
|
|
34
|
+
*/
|
|
35
|
+
public bounds: Bounds;
|
|
36
|
+
/**
|
|
37
|
+
* The collision shapes of the body
|
|
38
|
+
* @ignore
|
|
39
|
+
* @type {Polygon[]|Line[]|Ellipse[]|Point|Point[]}
|
|
40
|
+
*/
|
|
41
|
+
shapes: Polygon[] | Line[] | Ellipse[] | Point | Point[];
|
|
42
|
+
/**
|
|
43
|
+
* The body collision mask, that defines what should collide with what.<br>
|
|
44
|
+
* (by default will collide with all entities)
|
|
45
|
+
* @ignore
|
|
46
|
+
* @type {number}
|
|
47
|
+
* @default collision.types.ALL_OBJECT
|
|
48
|
+
* @see collision.types
|
|
49
|
+
*/
|
|
50
|
+
collisionMask: number;
|
|
51
|
+
/**
|
|
52
|
+
* define the collision type of the body for collision filtering
|
|
53
|
+
* @public
|
|
54
|
+
* @type {number}
|
|
55
|
+
* @default collision.types.ENEMY_OBJECT
|
|
56
|
+
* @see collision.types
|
|
57
|
+
* @example
|
|
58
|
+
* // set the body collision type
|
|
59
|
+
* body.collisionType = me.collision.types.PLAYER_OBJECT;
|
|
60
|
+
*/
|
|
61
|
+
public collisionType: number;
|
|
62
|
+
/**
|
|
63
|
+
* The current velocity of the body.
|
|
64
|
+
* See to apply a force if you need to modify a body velocity
|
|
65
|
+
* @see Body.force
|
|
66
|
+
* @public
|
|
67
|
+
* @type {Vector2d}
|
|
68
|
+
* @default <0,0>
|
|
69
|
+
*/
|
|
70
|
+
public vel: Vector2d;
|
|
71
|
+
/**
|
|
72
|
+
* body force to apply to this the body in the current step.
|
|
73
|
+
* (any positive or negative force will be cancelled after every world/body update cycle)
|
|
74
|
+
* @public
|
|
75
|
+
* @type {Vector2d}
|
|
76
|
+
* @default <0,0>
|
|
77
|
+
* @see Body.setMaxVelocity
|
|
78
|
+
* @example
|
|
79
|
+
* // define a default maximum acceleration, initial force and friction
|
|
80
|
+
* this.body.force.set(1, 0);
|
|
81
|
+
* this.body.friction.set(0.4, 0);
|
|
82
|
+
* this.body.setMaxVelocity(3, 15);
|
|
83
|
+
*
|
|
84
|
+
* // apply a positive or negative force when pressing left of right key
|
|
85
|
+
* update(dt) {
|
|
86
|
+
* if (me.input.isKeyPressed("left")) {
|
|
87
|
+
* this.body.force.x = -this.body.maxVel.x;
|
|
88
|
+
* } else if (me.input.isKeyPressed("right")) {
|
|
89
|
+
* this.body.force.x = this.body.maxVel.x;
|
|
90
|
+
* }
|
|
91
|
+
* }
|
|
92
|
+
*/
|
|
93
|
+
public force: Vector2d;
|
|
94
|
+
/**
|
|
95
|
+
* body friction
|
|
96
|
+
* @public
|
|
97
|
+
* @type {Vector2d}
|
|
98
|
+
* @default <0,0>
|
|
99
|
+
*/
|
|
100
|
+
public friction: Vector2d;
|
|
101
|
+
/**
|
|
102
|
+
* the body bounciness level when colliding with other solid bodies :
|
|
103
|
+
* a value of 0 will not bounce, a value of 1 will fully rebound.
|
|
104
|
+
* @public
|
|
105
|
+
* @type {number}
|
|
106
|
+
* @default 0
|
|
107
|
+
*/
|
|
108
|
+
public bounce: number;
|
|
109
|
+
/**
|
|
110
|
+
* the body mass
|
|
111
|
+
* @public
|
|
112
|
+
* @type {number}
|
|
113
|
+
* @default 1
|
|
114
|
+
*/
|
|
115
|
+
public mass: number;
|
|
116
|
+
/**
|
|
117
|
+
* Current rotation angle (radians). Visual-only under the built-in
|
|
118
|
+
* SAT solver — the collision shapes themselves are NOT rotated by
|
|
119
|
+
* angular integration; only `renderable.currentTransform` is.
|
|
120
|
+
* Defaults to `0` and is integrated each step from
|
|
121
|
+
* {@link Body#angularVelocity}. Set directly via
|
|
122
|
+
* {@link Body#setAngle} or as a side effect of integration.
|
|
123
|
+
* @public
|
|
124
|
+
* @type {number}
|
|
125
|
+
* @default 0
|
|
126
|
+
* @example
|
|
127
|
+
* // teleport the sprite to face down-right (45°):
|
|
128
|
+
* sprite.body.angle = Math.PI / 4;
|
|
129
|
+
*/
|
|
130
|
+
public angle: number;
|
|
131
|
+
/**
|
|
132
|
+
* Angular velocity in radians per frame. Default `0` — bodies that
|
|
133
|
+
* never touch the angular API pay no integration cost. See
|
|
134
|
+
* {@link Body#setAngularVelocity} and {@link Body#applyTorque}.
|
|
135
|
+
* @public
|
|
136
|
+
* @type {number}
|
|
137
|
+
* @default 0
|
|
138
|
+
* @example
|
|
139
|
+
* // continuously spin a pickup at ~3°/frame (~180°/sec at 60fps):
|
|
140
|
+
* pickup.body.angularVelocity = 0.05;
|
|
141
|
+
*/
|
|
142
|
+
public angularVelocity: number;
|
|
143
|
+
/**
|
|
144
|
+
* Per-step exponential decay applied to {@link Body#angularVelocity}
|
|
145
|
+
* — analog of `frictionAir` for rotation. `0` = no damping
|
|
146
|
+
* (bodies spin forever); `1` = full damping per step (rotation
|
|
147
|
+
* stops instantly). Typical values are small (`0.01` – `0.05`)
|
|
148
|
+
* so spin decays naturally over a few seconds. Negative values
|
|
149
|
+
* are ignored (treated as `0`); values `> 1` flip the sign each
|
|
150
|
+
* step (overdamped — usually a foot-gun).
|
|
151
|
+
* @public
|
|
152
|
+
* @type {number}
|
|
153
|
+
* @default 0
|
|
154
|
+
* @example
|
|
155
|
+
* // dynamite barrel spins on impact then slows to a stop:
|
|
156
|
+
* barrel.body.angularDrag = 0.02;
|
|
157
|
+
* barrel.body.applyTorque(120);
|
|
158
|
+
*/
|
|
159
|
+
public angularDrag: number;
|
|
160
|
+
/**
|
|
161
|
+
* Moment-of-inertia analog used when converting force-at-offset
|
|
162
|
+
* and torque into angular velocity: `Δω = τ / pseudoInertia`.
|
|
163
|
+
* Defaults to a geometry-derived approximation
|
|
164
|
+
* `(width² + height²) / 12` matching the moment of inertia of a
|
|
165
|
+
* unit-mass rectangle. Override directly to make a body harder or
|
|
166
|
+
* easier to spin. Auto-recomputed after every {@link Body#addShape}
|
|
167
|
+
* call — manual overrides must come AFTER the body is fully built.
|
|
168
|
+
* @public
|
|
169
|
+
* @type {number}
|
|
170
|
+
* @default `(width² + height²) / 12`
|
|
171
|
+
* @example
|
|
172
|
+
* // a heavy boss is hard to knock around:
|
|
173
|
+
* boss.body.addShape(new me.Rect(0, 0, 64, 64));
|
|
174
|
+
* boss.body.pseudoInertia *= 10;
|
|
175
|
+
*/
|
|
176
|
+
public pseudoInertia: number;
|
|
177
|
+
/**
|
|
178
|
+
* max velocity (to limit body velocity)
|
|
179
|
+
* @public
|
|
180
|
+
* @type {Vector2d}
|
|
181
|
+
* @default <490,490>
|
|
182
|
+
*/
|
|
183
|
+
public maxVel: Vector2d;
|
|
184
|
+
/**
|
|
185
|
+
* Either this body is a static body or not.
|
|
186
|
+
* A static body is completely fixed and can never change position or angle.
|
|
187
|
+
* @readonly
|
|
188
|
+
* @public
|
|
189
|
+
* @type {boolean}
|
|
190
|
+
* @default false
|
|
191
|
+
*/
|
|
192
|
+
public readonly isStatic: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Whether this body is a sensor. A sensor detects collisions and
|
|
195
|
+
* fires the `onCollision*` events on the renderable, but does not
|
|
196
|
+
* physically respond to the contact (the SAT solver skips the
|
|
197
|
+
* positional push-out). Useful for triggers, ground-snap assists,
|
|
198
|
+
* etc. — same role as Matter's `isSensor`.
|
|
199
|
+
* @public
|
|
200
|
+
* @type {boolean}
|
|
201
|
+
* @default false
|
|
202
|
+
*/
|
|
203
|
+
public isSensor: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* The degree to which this body is affected by the world gravity
|
|
206
|
+
* @public
|
|
207
|
+
* @see {@link World.gravity}
|
|
208
|
+
* @type {number}
|
|
209
|
+
* @default 1.0
|
|
210
|
+
*/
|
|
211
|
+
public gravityScale: number;
|
|
212
|
+
/**
|
|
213
|
+
* If true this body won't be affected by the world gravity.
|
|
214
|
+
* @public
|
|
215
|
+
* @see {@link World.gravity}
|
|
216
|
+
* @type {boolean}
|
|
217
|
+
* @default false
|
|
218
|
+
* @deprecated since 19.5.0 — use `gravityScale = 0` (or
|
|
219
|
+
* `bodyDef.gravityScale = 0` at construction, or
|
|
220
|
+
* `body.setGravityScale(0)` at runtime) instead. `gravityScale`
|
|
221
|
+
* is part of the portable {@link PhysicsBody} surface and works
|
|
222
|
+
* on every adapter; `ignoreGravity` is a builtin-only field that
|
|
223
|
+
* the matter adapter silently ignores. The two-field check
|
|
224
|
+
* (`!ignoreGravity && gravityScale !== 0`) used by builtin is
|
|
225
|
+
* redundant — set `gravityScale = 0` and both branches agree.
|
|
226
|
+
*/
|
|
227
|
+
public ignoreGravity: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* falling state of the body<br>
|
|
230
|
+
* true if the object is falling<br>
|
|
231
|
+
* false if the object is standing on something<br>
|
|
232
|
+
* @readonly
|
|
233
|
+
* @public
|
|
234
|
+
* @type {boolean}
|
|
235
|
+
* @default false
|
|
236
|
+
*/
|
|
237
|
+
public readonly falling: boolean;
|
|
238
|
+
/**
|
|
239
|
+
* jumping state of the body<br>
|
|
240
|
+
* equal true if the body is jumping<br>
|
|
241
|
+
* @readonly
|
|
242
|
+
* @public
|
|
243
|
+
* @type {boolean}
|
|
244
|
+
* @default false
|
|
245
|
+
*/
|
|
246
|
+
public readonly jumping: boolean;
|
|
247
|
+
onBodyUpdate: Function | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* set the body as a static body
|
|
250
|
+
* static body do not move automatically and do not check against collision with others
|
|
251
|
+
* @param {boolean} [isStatic=true]
|
|
252
|
+
*/
|
|
253
|
+
setStatic(isStatic?: boolean): void;
|
|
254
|
+
/**
|
|
255
|
+
* set this body's linear velocity. Portable across physics adapters —
|
|
256
|
+
* under the builtin adapter this mutates `body.vel`; under Matter it
|
|
257
|
+
* delegates to `Matter.Body.setVelocity`.
|
|
258
|
+
* @param {number} x - velocity along the X axis
|
|
259
|
+
* @param {number} y - velocity along the Y axis
|
|
260
|
+
*/
|
|
261
|
+
setVelocity(x: number, y: number): void;
|
|
262
|
+
/**
|
|
263
|
+
* read this body's linear velocity into an optional output vector.
|
|
264
|
+
* @param {Vector2d} [out] - vector to write into; a new Vector2d is
|
|
265
|
+
* allocated when omitted
|
|
266
|
+
* @returns {Vector2d}
|
|
267
|
+
*/
|
|
268
|
+
getVelocity(out?: Vector2d): Vector2d;
|
|
269
|
+
/**
|
|
270
|
+
* accumulate a force on this body for the current step. Repeated calls
|
|
271
|
+
* within a single update add together; the engine clears the
|
|
272
|
+
* accumulator at the end of each integration step. Force magnitude
|
|
273
|
+
* conventions differ between adapters — consult the active adapter's
|
|
274
|
+
* docs for tuning ranges (builtin: px/frame²; Matter: Newtonian
|
|
275
|
+
* `force/mass·dt²`, typically ~100× smaller than builtin).
|
|
276
|
+
* @param {number} x - force along the X axis
|
|
277
|
+
* @param {number} y - force along the Y axis
|
|
278
|
+
* @param {number} [pointX] - world X of the application point; when
|
|
279
|
+
* present (along with `pointY`) and different from the body centroid,
|
|
280
|
+
* the resulting lever arm generates a torque
|
|
281
|
+
* `τ = (r.x · F.y) − (r.y · F.x)` that bumps {@link Body#angularVelocity}
|
|
282
|
+
* by `τ / pseudoInertia`. Omit both `pointX` and `pointY` for the
|
|
283
|
+
* linear-only behaviour that's compatible with code written before
|
|
284
|
+
* the angular API was added.
|
|
285
|
+
* @param {number} [pointY] - world Y of the application point
|
|
286
|
+
* @example
|
|
287
|
+
* // pure linear thrust (2-arg form, unchanged behaviour):
|
|
288
|
+
* ship.body.applyForce(0, -0.05);
|
|
289
|
+
*
|
|
290
|
+
* // off-centre push on a crate: the contact point at the top of the
|
|
291
|
+
* // crate is above its centroid, so the same horizontal force now
|
|
292
|
+
* // both translates AND tips the crate forward.
|
|
293
|
+
* const topX = crate.pos.x + crate.width / 2;
|
|
294
|
+
* const topY = crate.pos.y;
|
|
295
|
+
* crate.body.applyForce(1.5, 0, topX, topY);
|
|
296
|
+
*
|
|
297
|
+
* // wind pushing on the top of a flag-pole: pole tilts, base stays put
|
|
298
|
+
* // (only meaningful here if the base is anchored / static).
|
|
299
|
+
* pole.body.applyForce(0.3, 0, pole.pos.x + pole.width / 2, pole.pos.y);
|
|
300
|
+
*/
|
|
301
|
+
applyForce(x: number, y: number, pointX?: number, pointY?: number): void;
|
|
302
|
+
/**
|
|
303
|
+
* Apply an instantaneous angular impulse: `Δω = τ / pseudoInertia`.
|
|
304
|
+
* The angular analog of {@link Body#applyImpulse} — bypasses the
|
|
305
|
+
* lever-arm computation in {@link Body#applyForce} for the
|
|
306
|
+
* "just spin this up directly" case (a power-up's intrinsic spin,
|
|
307
|
+
* an explicit thruster, a knockback spin effect on hit).
|
|
308
|
+
* @param {number} torque - angular impulse magnitude. Positive values
|
|
309
|
+
* produce clockwise rotation on screen (matching the Y-down canvas
|
|
310
|
+
* convention); negative values rotate counter-clockwise.
|
|
311
|
+
* @example
|
|
312
|
+
* // give a pickup a one-shot spin-up when collected:
|
|
313
|
+
* pickup.body.applyTorque(80);
|
|
314
|
+
*
|
|
315
|
+
* // explosion knockback that both pushes and spins:
|
|
316
|
+
* crate.body.applyImpulse(impulseX, impulseY);
|
|
317
|
+
* crate.body.applyTorque((Math.random() - 0.5) * 100);
|
|
318
|
+
*/
|
|
319
|
+
applyTorque(torque: number): void;
|
|
320
|
+
/**
|
|
321
|
+
* Set angular velocity directly. Bypasses inertia — the value is the
|
|
322
|
+
* actual rad/frame that integration will apply next step. Use this
|
|
323
|
+
* for "set and hold" rotation (a coin that always spins at the same
|
|
324
|
+
* rate); use {@link Body#applyTorque} for impulse-style spin-up.
|
|
325
|
+
* @param {number} omega - target angular velocity (rad / frame)
|
|
326
|
+
* @example
|
|
327
|
+
* // make a fan blade spin at a fixed rate:
|
|
328
|
+
* fan.body.setAngularVelocity(0.1); // ~6°/frame
|
|
329
|
+
*/
|
|
330
|
+
setAngularVelocity(omega: number): void;
|
|
331
|
+
/**
|
|
332
|
+
* Read current angular velocity (rad / frame).
|
|
333
|
+
* @returns {number}
|
|
334
|
+
* @example
|
|
335
|
+
* // freeze rotation if the body is spinning too fast:
|
|
336
|
+
* if (Math.abs(body.getAngularVelocity()) > 2) {
|
|
337
|
+
* body.setAngularVelocity(0);
|
|
338
|
+
* }
|
|
339
|
+
*/
|
|
340
|
+
getAngularVelocity(): number;
|
|
341
|
+
/**
|
|
342
|
+
* Set absolute rotation angle (radians). Updates the body's `angle`
|
|
343
|
+
* field and re-syncs the renderable's `currentTransform` immediately
|
|
344
|
+
* so the visual rotation reflects the new value without waiting for
|
|
345
|
+
* the next integration step.
|
|
346
|
+
* @param {number} rad - target angle in radians
|
|
347
|
+
* @example
|
|
348
|
+
* // turret aims at the player every frame:
|
|
349
|
+
* const dx = player.centerX - turret.centerX;
|
|
350
|
+
* const dy = player.centerY - turret.centerY;
|
|
351
|
+
* turret.body.setAngle(Math.atan2(dy, dx));
|
|
352
|
+
*/
|
|
353
|
+
setAngle(rad: number): void;
|
|
354
|
+
/**
|
|
355
|
+
* Read absolute rotation angle (radians).
|
|
356
|
+
* @returns {number}
|
|
357
|
+
*/
|
|
358
|
+
getAngle(): number;
|
|
359
|
+
/**
|
|
360
|
+
* Sync `this.angle` to the renderable's `currentTransform`. Pivot is
|
|
361
|
+
* the body's bounds center (matches the matter adapter's rotation
|
|
362
|
+
* pivot — see `MatterAdapter.syncFromPhysics`). Internal helper used
|
|
363
|
+
* by both the per-step integrator and {@link Body#setAngle}.
|
|
364
|
+
* @ignore
|
|
365
|
+
*/
|
|
366
|
+
_syncAngleTransform(): void;
|
|
367
|
+
/**
|
|
368
|
+
* apply an instantaneous impulse to this body — a single-step velocity
|
|
369
|
+
* change scaled by inverse mass (`dv = J / m`). Useful for one-shot
|
|
370
|
+
* events like a cue strike, projectile launch, or knockback, where
|
|
371
|
+
* mass should influence the resulting velocity change. Repeated calls
|
|
372
|
+
* within a single update accumulate. Static bodies (mass 0) ignore
|
|
373
|
+
* the call. Identical signature on the Matter adapter, where the
|
|
374
|
+
* adapter integrates the impulse the same way (matter has no native
|
|
375
|
+
* `applyImpulse`).
|
|
376
|
+
* @param {number} x - impulse along the X axis
|
|
377
|
+
* @param {number} y - impulse along the Y axis
|
|
378
|
+
*/
|
|
379
|
+
applyImpulse(x: number, y: number): void;
|
|
380
|
+
/**
|
|
381
|
+
* set this body's mass. Useful for variable-mass entities (projectiles
|
|
382
|
+
* loaded with ammo, weight pickups, characters carrying objects).
|
|
383
|
+
* Mass affects `applyImpulse` (via `dv = J / m`) and the proportional
|
|
384
|
+
* push-out response in dynamic-dynamic collisions. A mass of 0 makes
|
|
385
|
+
* the body inert to forces and impulses (without going static).
|
|
386
|
+
* @param {number} m - new mass, non-negative
|
|
387
|
+
*/
|
|
388
|
+
setMass(m: number): void;
|
|
389
|
+
/**
|
|
390
|
+
* set this body's restitution / bounce factor. `0` = no bounce (energy
|
|
391
|
+
* absorbed on contact); `1` = perfect elastic rebound; values in
|
|
392
|
+
* between dampen the rebound. Applied by `Body.respondToCollision` —
|
|
393
|
+
* see `BuiltinAdapter` docs for the cancellation math.
|
|
394
|
+
*
|
|
395
|
+
* Matches the `bodyDef.restitution` field name used at registration
|
|
396
|
+
* time; the body-side property has historically been called `bounce`,
|
|
397
|
+
* which is the canonical legacy name and is preserved.
|
|
398
|
+
* @param {number} r - restitution factor, typically in [0, 1]
|
|
399
|
+
*/
|
|
400
|
+
setBounce(r: number): void;
|
|
401
|
+
/**
|
|
402
|
+
* set this body's per-body gravity multiplier. `1` = world gravity
|
|
403
|
+
* (default), `0` = ignore world gravity (e.g. flying enemy, underwater
|
|
404
|
+
* float), `2` = 2× gravity (heavy-feel objects). Multiplied with the
|
|
405
|
+
* world's `gravity.y` each frame inside `applyGravity`.
|
|
406
|
+
* @param {number} scale - gravity scale factor
|
|
407
|
+
*/
|
|
408
|
+
setGravityScale(scale: number): void;
|
|
409
|
+
/**
|
|
410
|
+
* toggle this body between solid and sensor. Sensor bodies still emit
|
|
411
|
+
* collision events (`onCollisionStart`, `onCollisionActive`,
|
|
412
|
+
* `onCollisionEnd`) but the solver does not physically resolve the
|
|
413
|
+
* contact — same semantics as Matter's `isSensor`. Useful for one-way
|
|
414
|
+
* platforms, trigger zones, and ground-snap assists.
|
|
415
|
+
* @param {boolean} [isSensor=true]
|
|
416
|
+
*/
|
|
417
|
+
setSensor(isSensor?: boolean): void;
|
|
418
|
+
/**
|
|
419
|
+
* add a collision shape to this body <br>
|
|
420
|
+
* (note: me.Rect objects will be converted to me.Polygon before being added)
|
|
421
|
+
* @param {Rect|Polygon|Line|Ellipse|Point|Point[]|Bounds|object} shape - a shape or JSON object
|
|
422
|
+
* @returns {number} the shape array length
|
|
423
|
+
* @example
|
|
424
|
+
* // add a rectangle shape
|
|
425
|
+
* this.body.addShape(new me.Rect(0, 0, image.width, image.height));
|
|
426
|
+
* // add a shape from a JSON object
|
|
427
|
+
* this.body.addShape(me.loader.getJSON("shapesdef").banana);
|
|
428
|
+
*/
|
|
429
|
+
addShape(shape: Rect | Polygon | Line | Ellipse | Point | Point[] | Bounds | object): number;
|
|
430
|
+
/**
|
|
431
|
+
* Recompute the default `pseudoInertia` from the current bounds.
|
|
432
|
+
* Uses the moment-of-inertia formula for a unit-mass rectangle —
|
|
433
|
+
* `(width² + height²) / 12` — which gives a value that scales
|
|
434
|
+
* sensibly with body size: a small body resists rotation less, a
|
|
435
|
+
* large body more. Clamped to a minimum of 1 to keep divisions
|
|
436
|
+
* well-defined even on degenerate 0-size bodies.
|
|
437
|
+
* @ignore
|
|
438
|
+
*/
|
|
439
|
+
_recomputePseudoInertia(): void;
|
|
440
|
+
/**
|
|
441
|
+
* set the body vertices to the given one
|
|
442
|
+
* @param {Vector2d[]} vertices - an array of me.Vector2d points defining a convex hull
|
|
443
|
+
* @param {number} [index=0] - the shape object for which to set the vertices
|
|
444
|
+
* @param {boolean} [clear=true] - either to reset the body definition before adding the new vertices
|
|
445
|
+
*/
|
|
446
|
+
setVertices(vertices: Vector2d[], index?: number, clear?: boolean): void;
|
|
447
|
+
/**
|
|
448
|
+
* add the given vertices to the body shape
|
|
449
|
+
* @param {Vector2d[]} vertices - an array of me.Vector2d points defining a convex hull
|
|
450
|
+
* @param {number} [index=0] - the shape object for which to set the vertices
|
|
451
|
+
*/
|
|
452
|
+
addVertices(vertices: Vector2d[], index?: number): void;
|
|
453
|
+
/**
|
|
454
|
+
* add collision mesh based on a JSON object
|
|
455
|
+
* (this will also apply any physic properties defined in the given JSON file)
|
|
456
|
+
* @param {object} json - a JSON object as exported from a Physics Editor tool
|
|
457
|
+
* @param {string} [id] - an optional shape identifier within the given the json object
|
|
458
|
+
* @see https://www.codeandweb.com/physicseditor
|
|
459
|
+
* @returns {number} how many shapes were added to the body
|
|
460
|
+
* @example
|
|
461
|
+
* // define the body based on the banana shape
|
|
462
|
+
* this.body.fromJSON(me.loader.getJSON("shapesdef").banana);
|
|
463
|
+
* // or ...
|
|
464
|
+
* this.body.fromJSON(me.loader.getJSON("shapesdef"), "banana");
|
|
465
|
+
*/
|
|
466
|
+
fromJSON(json: object, id?: string): number;
|
|
467
|
+
/**
|
|
468
|
+
* return the collision shape at the given index
|
|
469
|
+
* @param {number} [index=0] - the shape object at the specified index
|
|
470
|
+
* @returns {Polygon|Line|Ellipse} shape a shape object if defined
|
|
471
|
+
*/
|
|
472
|
+
getShape(index?: number): Polygon | Line | Ellipse;
|
|
473
|
+
/**
|
|
474
|
+
* returns the AABB bounding box for this body
|
|
475
|
+
* @returns {Bounds} bounding box Rectangle object
|
|
476
|
+
*/
|
|
477
|
+
getBounds(): Bounds;
|
|
478
|
+
/**
|
|
479
|
+
* remove the specified shape from the body shape list
|
|
480
|
+
* @param {Polygon|Line|Ellipse} shape - a shape object
|
|
481
|
+
* @returns {number} the shape array length
|
|
482
|
+
*/
|
|
483
|
+
removeShape(shape: Polygon | Line | Ellipse): number;
|
|
484
|
+
/**
|
|
485
|
+
* remove the shape at the given index from the body shape list
|
|
486
|
+
* @param {number} index - the shape object at the specified index
|
|
487
|
+
* @returns {number} the shape array length
|
|
488
|
+
*/
|
|
489
|
+
removeShapeAt(index: number): number;
|
|
490
|
+
/**
|
|
491
|
+
* By default all physic bodies are able to collide with all other bodies, <br>
|
|
492
|
+
* but it's also possible to specify 'collision filters' to provide a finer <br>
|
|
493
|
+
* control over which body can collide with each other.
|
|
494
|
+
* @see collision.types
|
|
495
|
+
* @param {number} [bitmask = collision.types.ALL_OBJECT] - the collision mask
|
|
496
|
+
* @example
|
|
497
|
+
* // filter collision detection with collision shapes, enemies and collectables
|
|
498
|
+
* body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
|
|
499
|
+
* ...
|
|
500
|
+
* // disable collision detection with all other objects
|
|
501
|
+
* body.setCollisionMask(me.collision.types.NO_OBJECT);
|
|
502
|
+
*/
|
|
503
|
+
setCollisionMask(bitmask?: number): void;
|
|
504
|
+
/**
|
|
505
|
+
* define the collision type of the body for collision filtering
|
|
506
|
+
* @see collision.types
|
|
507
|
+
* @param {number} type - the collision type
|
|
508
|
+
* @example
|
|
509
|
+
* // set the body collision type
|
|
510
|
+
* body.collisionType = me.collision.types.PLAYER_OBJECT;
|
|
511
|
+
*/
|
|
512
|
+
setCollisionType(type: number): void;
|
|
513
|
+
/**
|
|
514
|
+
* the built-in function to solve the collision response
|
|
515
|
+
* @param {ResponseObject} response - the collision response object
|
|
516
|
+
* @see {@link ResponseObject}
|
|
517
|
+
*/
|
|
518
|
+
respondToCollision(response: ResponseObject): void;
|
|
519
|
+
/**
|
|
520
|
+
* The forEach() method executes a provided function once per body shape element. <br>
|
|
521
|
+
* the callback function is invoked with three arguments: <br>
|
|
522
|
+
* - The current element being processed in the array <br>
|
|
523
|
+
* - The index of element in the array. <br>
|
|
524
|
+
* - The array forEach() was called upon. <br>
|
|
525
|
+
* @param {Function} callback - function to execute on each element
|
|
526
|
+
* @param {object} [thisArg] - value to use as this(i.e reference Object) when executing callback.
|
|
527
|
+
* @example
|
|
528
|
+
* // iterate through all shapes of the physic body
|
|
529
|
+
* mySprite.body.forEach((shape) => {
|
|
530
|
+
* shape.doSomething();
|
|
531
|
+
* });
|
|
532
|
+
* mySprite.body.forEach((shape, index) => { ... });
|
|
533
|
+
* mySprite.body.forEach((shape, index, array) => { ... });
|
|
534
|
+
* mySprite.body.forEach((shape, index, array) => { ... }, thisArg);
|
|
535
|
+
*/
|
|
536
|
+
forEach(callback: Function, thisArg?: object): void;
|
|
537
|
+
/**
|
|
538
|
+
* Returns true if the any of the shape composing the body contains the given point.
|
|
539
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to check
|
|
540
|
+
* @param {number} [y] - y coordinate
|
|
541
|
+
* @returns {boolean} true if contains
|
|
542
|
+
* @example
|
|
543
|
+
* if (mySprite.body.contains(10, 10)) {
|
|
544
|
+
* // do something
|
|
545
|
+
* }
|
|
546
|
+
* // or
|
|
547
|
+
* if (mySprite.body.contains(myVector2d)) {
|
|
548
|
+
* // do something
|
|
549
|
+
* }
|
|
550
|
+
*/
|
|
551
|
+
contains(...args: any[]): boolean;
|
|
552
|
+
/**
|
|
553
|
+
* Rotate this body (counter-clockwise) by the specified angle (in radians).
|
|
554
|
+
* Unless specified the body will be rotated around its center point
|
|
555
|
+
* @param {number} angle - The angle to rotate (in radians)
|
|
556
|
+
* @param {Vector2d} [v=Body.getBounds().center] - an optional point to rotate around
|
|
557
|
+
* @returns {Body} Reference to this object for method chaining
|
|
558
|
+
*/
|
|
559
|
+
rotate(angle: number, v?: Vector2d): Body;
|
|
560
|
+
/**
|
|
561
|
+
* cap the body velocity (body.maxVel property) to the specified value<br>
|
|
562
|
+
* @param {number} x - max velocity on x axis
|
|
563
|
+
* @param {number} y - max velocity on y axis
|
|
564
|
+
*/
|
|
565
|
+
setMaxVelocity(x: number, y: number): void;
|
|
566
|
+
/**
|
|
567
|
+
* set the body default friction
|
|
568
|
+
* @param {number} x - horizontal friction
|
|
569
|
+
* @param {number} y - vertical friction
|
|
570
|
+
*/
|
|
571
|
+
setFriction(x?: number, y?: number): void;
|
|
572
|
+
/**
|
|
573
|
+
* Updates the parent's position as well as computes the new body's velocity based
|
|
574
|
+
* on the values of force/friction. Velocity changes are proportional to the
|
|
575
|
+
* me.timer.tick value (which can be used to scale velocities). The approach to moving the
|
|
576
|
+
* parent renderable is to compute new values of the Body.vel property then add them to
|
|
577
|
+
* the parent.pos value thus changing the position by the amount of Body.vel each time the
|
|
578
|
+
* update call is made. <br>
|
|
579
|
+
* Updates to Body.vel are bounded by maxVel (which defaults to viewport size if not set) <br>
|
|
580
|
+
* At this time a call to Body.Update does not call the onBodyUpdate callback that is listed in the constructor arguments.
|
|
581
|
+
* @protected
|
|
582
|
+
* @param {number} dt - time since the last update in milliseconds.
|
|
583
|
+
* @returns {boolean} true if resulting velocity is different than 0
|
|
584
|
+
*/
|
|
585
|
+
protected update(): boolean;
|
|
586
|
+
/**
|
|
587
|
+
* Destroy function<br>
|
|
588
|
+
* @ignore
|
|
589
|
+
*/
|
|
590
|
+
destroy(): void;
|
|
591
|
+
}
|
|
592
|
+
import type Renderable from "../../renderable/renderable.js";
|
|
593
|
+
import type Container from "../../renderable/container.js";
|
|
594
|
+
import type Entity from "../../renderable/entity/entity.js";
|
|
595
|
+
import type Sprite from "../../renderable/sprite.js";
|
|
596
|
+
import type NineSliceSprite from "../../renderable/nineslicesprite.js";
|
|
597
|
+
import { Bounds } from "../bounds.ts";
|
|
598
|
+
import { Polygon } from "../../geometries/polygon.ts";
|
|
599
|
+
import { Line } from "../../geometries/line.ts";
|
|
600
|
+
import { Ellipse } from "../../geometries/ellipse.ts";
|
|
601
|
+
import { Point } from "../../geometries/point.ts";
|
|
602
|
+
import { Vector2d } from "../../math/vector2d.ts";
|
|
603
|
+
import { Rect } from "../../geometries/rectangle.ts";
|
|
604
|
+
import type ResponseObject from "../response.js";
|
|
605
|
+
//# sourceMappingURL=body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../../src/physics/builtin/body.js"],"names":[],"mappings":"AAaA;;;;;;;;IAQI;AAEJ;;;;GAIG;AACH;IACC;;;;OAIG;IACH,sBAJW,UAAU,GAAC,SAAS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