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

Method setText

packages/melonjs/src/renderable/text/bitmaptext.js:175–194  ·  view source on GitHub ↗

* change the text to be displayed * @param {number|string|string[]} value - a string, or an array of strings * @returns {BitmapText} this object for chaining

(value = "")

Source from the content-addressed store, hash-verified

173 * @returns {BitmapText} this object for chaining
174 */
175 setText(value = "") {
176 if (this._text.toString() !== value.toString()) {
177 if (!Array.isArray(value)) {
178 this._text = ("" + value).split("\n");
179 } else {
180 this._text = value;
181 }
182 this.isDirty = true;
183 }
184
185 if (this._text.length > 0 && this.wordWrapWidth > 0) {
186 this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth);
187 }
188
189 // measure text dimensions (cached for updateBounds)
190 this.metrics.measureText(this._text);
191 this.updateBounds();
192
193 return this;
194 }
195
196 /**
197 * the number of characters to display (use -1 to show all).

Callers 2

constructorMethod · 0.95
onResetEventMethod · 0.95

Calls 5

updateBoundsMethod · 0.95
wordWrapMethod · 0.80
splitMethod · 0.65
toStringMethod · 0.45
measureTextMethod · 0.45

Tested by

no test coverage detected