MCPcopy Create free account
hub / github.com/melonjs/melonJS / constructor

Method constructor

packages/melonjs/src/renderable/collectable.js:16–58  ·  view source on GitHub ↗

* @param {number} x - the x coordinates of the collectable * @param {number} y - the y coordinates of the collectable * @param {object} settings - See Sprite

(x, y, settings)

Source from the content-addressed store, hash-verified

14 * @param {object} settings - See {@link Sprite}
15 */
16 constructor(x, y, settings) {
17 // call the super constructor
18 super(x, y, settings);
19
20 this.name = settings.name;
21 this.type = settings.type;
22 this.id = settings.id;
23
24 // add and configure the physic body
25 let shape = settings.shapes;
26 if (typeof shape === "undefined") {
27 shape = polygonPool.get(0, 0, [
28 vector2dPool.get(0, 0),
29 vector2dPool.get(this.width, 0),
30 vector2dPool.get(this.width, this.height),
31 ]);
32 }
33 // declarative body — adapter-portable, auto-registered on addChild.
34 // `isSensor: true` matches the documented intent ("immovable
35 // object, picked up on overlap"): collision events still fire so
36 // the pickup callback runs, but the solver does not physically
37 // push the player away. Under the builtin adapter this is a
38 // no-op for Collectable subclasses that don't define
39 // `onCollision` (the SAT detector already skipped push-out);
40 // under Matter it is required — matter's solver always resolves
41 // contacts unless a body is flagged as a sensor.
42 this.bodyDef = {
43 type: "static",
44 shapes: Array.isArray(shape) ? shape : [shape],
45 collisionType: collision.types.COLLECTABLE_OBJECT,
46 // by default only collides with PLAYER_OBJECT
47 collisionMask: collision.types.PLAYER_OBJECT,
48 isSensor: true,
49 };
50
51 // Update anchorPoint
52 if (settings.anchorPoint) {
53 this.anchorPoint.set(settings.anchorPoint.x, settings.anchorPoint.y);
54 } else {
55 // for backward compatibility
56 this.anchorPoint.set(0, 0);
57 }
58 }
59}

Callers

nothing calls this directly

Calls 2

getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected