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

Method constructor

packages/melonjs/src/renderable/trail.js:60–99  ·  view source on GitHub ↗

* @param {object} [options] - trail options * @param {Renderable|Vector2d} [options.target] - auto-follow target * @param {number} [options.length=20] - max number of points * @param {number} [options.lifetime=500] - point lifetime in ms * @param {number} [options.minDistance=4] - min distan

(options = {})

Source from the content-addressed store, hash-verified

58 * @param {string} [options.blendMode="normal"] - blend mode
59 */
60 constructor(options = {}) {
61 super(0, 0, 1, 1);
62
63 /** @type {Renderable|Vector2d|null} */
64 this.target = options.target ?? null;
65 /** @type {number} */
66 this.maxPoints = options.length ?? 20;
67 /** @type {number} */
68 this.lifetime = options.lifetime ?? 500;
69 /** @type {number} */
70 this.minDistance = options.minDistance ?? 4;
71 /** @type {number} */
72 this.width = options.width ?? 10;
73 /** @type {number[]} */
74 this.widthCurve =
75 Array.isArray(options.widthCurve) && options.widthCurve.length > 0
76 ? options.widthCurve
77 : [1, 0];
78
79 /** @ignore */
80 this._gradient = this._buildGradient(options);
81 /** @ignore */
82 this._points = [];
83 /** @ignore */
84 this._segmentColor = colorPool.get();
85 /** @ignore */
86 this._n0 = { x: 0, y: 0 };
87 /** @ignore */
88 this._n1 = { x: 0, y: 0 };
89
90 this.alwaysUpdate = true;
91 this.anchorPoint.set(0, 0);
92
93 if (typeof options.opacity === "number") {
94 this.setOpacity(options.opacity);
95 }
96 if (options.blendMode) {
97 this.blendMode = options.blendMode;
98 }
99 }
100
101 /**
102 * add a point to the trail

Callers

nothing calls this directly

Calls 4

_buildGradientMethod · 0.95
getMethod · 0.65
setMethod · 0.45
setOpacityMethod · 0.45

Tested by

no test coverage detected