* @param {number} x - the x coordinates of the trigger area * @param {number} y - the y coordinates of the trigger area * @param {Object} settings - trigger settings * @param {number} [settings.width] - width of the trigger area * @param {number} [settings.height] - height of the trigger are
(x, y, settings)
| 68 | * })); |
| 69 | */ |
| 70 | constructor(x, y, settings) { |
| 71 | super(x, y, settings.width || 0, settings.height || 0); |
| 72 | |
| 73 | this.anchorPoint.set(0, 0); |
| 74 | |
| 75 | this.color = settings.color || settings.fade; |
| 76 | this.duration = settings.duration; |
| 77 | this.transition = settings.transition || "fade"; |
| 78 | this.transitionShape = settings.shape; |
| 79 | this.fading = false; |
| 80 | |
| 81 | // Tiled settings |
| 82 | this.name = "Trigger"; |
| 83 | this.type = settings.type; |
| 84 | this.id = settings.id; |
| 85 | this.gotolevel = settings.to; |
| 86 | |
| 87 | // collect the defined trigger settings |
| 88 | this.triggerSettings = { |
| 89 | event: "level", |
| 90 | }; |
| 91 | |
| 92 | for (const property of [ |
| 93 | "type", |
| 94 | "container", |
| 95 | "onLoaded", |
| 96 | "flatten", |
| 97 | "setViewportBounds", |
| 98 | "to", |
| 99 | ]) { |
| 100 | if (typeof settings[property] !== "undefined") { |
| 101 | this.triggerSettings[property] = settings[property]; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // add and configure the physic body |
| 106 | let shape = settings.shapes; |
| 107 | if (typeof shape === "undefined") { |
| 108 | shape = polygonPool.get(0, 0, [ |
| 109 | vector2dPool.get(0, 0), |
| 110 | vector2dPool.get(this.width, 0), |
| 111 | vector2dPool.get(this.width, this.height), |
| 112 | ]); |
| 113 | } |
| 114 | // declarative body — adapter-portable, auto-registered on addChild. |
| 115 | // `isSensor: true` makes the trigger explicitly a detection-only |
| 116 | // volume. Under the builtin adapter this is a no-op for triggers |
| 117 | // (the SAT detector already skipped push-out because Trigger |
| 118 | // doesn't define `onCollision`); under Matter it is required — |
| 119 | // matter's solver always resolves contacts unless the body is |
| 120 | // flagged as a sensor. |
| 121 | this.bodyDef = { |
| 122 | type: "static", |
| 123 | shapes: Array.isArray(shape) ? shape : [shape], |
| 124 | collisionType: collision.types.ACTION_OBJECT, |
| 125 | collisionMask: collision.types.PLAYER_OBJECT, |
| 126 | isSensor: true, |
| 127 | }; |