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

Method _drawFont

packages/melonjs/src/renderable/text/text.js:470–499  ·  view source on GitHub ↗

* @ignore

(context, text, x, y)

Source from the content-addressed store, hash-verified

468 * @ignore
469 */
470 _drawFont(context, text, x, y) {
471 setContextStyle(context, this);
472
473 let remaining = this.visibleCharacters;
474
475 for (let i = 0; i < text.length; i++) {
476 let string = text[i].trimEnd();
477
478 // limit visible characters if needed
479 if (remaining !== -1) {
480 if (remaining <= 0) {
481 break;
482 }
483 string = string.substring(0, remaining);
484 remaining -= string.length;
485 }
486
487 // draw the string
488 if (this.fillStyle.alpha > 0) {
489 context.fillText(string, x, y);
490 }
491 // stroke the text
492 if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
493 context.strokeText(string, x, y);
494 }
495 // add leading space
496 y += this.metrics.lineHeight();
497 }
498 return this.metrics;
499 }
500
501 /**
502 * Destroy function

Callers 2

setTextMethod · 0.95
drawMethod · 0.95

Calls 2

setContextStyleFunction · 0.85
lineHeightMethod · 0.80

Tested by

no test coverage detected