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

Method draw

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

* draw a text at the specified coord * @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance

(renderer)

Source from the content-addressed store, hash-verified

438 * @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
439 */
440 draw(renderer) {
441 // re-render the canvas texture when dirty (e.g. visibleCharacters changed)
442 if (this.isDirty) {
443 this.canvasTexture.invalidate(renderer);
444 this.canvasTexture.clear();
445 this._drawFont(
446 this.canvasTexture.context,
447 this._text,
448 this.pos.x - this.metrics.x,
449 this.pos.y - this.metrics.y,
450 );
451 }
452
453 // adjust x,y position based on the bounding box
454 let x = this.metrics.x;
455 let y = this.metrics.y;
456
457 // clamp to pixel grid if required
458 if (renderer.settings.subPixel === false) {
459 x = ~~x;
460 y = ~~y;
461 }
462
463 // draw the text
464 renderer.drawImage(this.canvasTexture.canvas, x, y);
465 }
466
467 /**
468 * @ignore

Callers

nothing calls this directly

Calls 4

_drawFontMethod · 0.95
invalidateMethod · 0.80
clearMethod · 0.65
drawImageMethod · 0.45

Tested by

no test coverage detected