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

Method draw

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

* draw the bitmap font * @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance

(renderer)

Source from the content-addressed store, hash-verified

348 * @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
349 */
350 draw(renderer) {
351 let x = this.pos.x;
352 let y = this.pos.y;
353
354 const lX = x;
355 const stringHeight = this.metrics.lineHeight();
356 const gy = this.metrics.glyphYOffset || 0;
357 const h = this.metrics.height;
358
359 // apply baseline shift once for the entire text block
360 switch (this.textBaseline) {
361 case "middle":
362 y -= gy + h * 0.5;
363 break;
364
365 case "ideographic":
366 case "alphabetic":
367 case "bottom":
368 y -= gy + h;
369 break;
370
371 default:
372 break;
373 }
374
375 // running character counter for visibleCharacters
376 let charCount = 0;
377 const maxChars = this.visibleCharacters;
378
379 for (let i = 0; i < this._text.length; i++) {
380 x = lX;
381 const string = this._text[i].trimEnd();
382 // adjust x pos based on alignment value
383 const stringWidth = this.metrics.lineWidth(string);
384 switch (this.textAlign) {
385 case "right":
386 x -= stringWidth;
387 break;
388
389 case "center":
390 x -= stringWidth * 0.5;
391 break;
392
393 default:
394 break;
395 }
396
397 // draw the string
398 let lastGlyph = null;
399 for (let c = 0, len = string.length; c < len; c++) {
400 // stop drawing when visibleCharacters limit is reached
401 if (maxChars !== -1 && charCount >= maxChars) {
402 return;
403 }
404
405 // calculate the char index
406 const ch = string.charCodeAt(c);
407 const glyph = this.fontData.glyphs[ch];

Callers

nothing calls this directly

Calls 4

lineHeightMethod · 0.80
getKerningMethod · 0.80
lineWidthMethod · 0.45
drawImageMethod · 0.45

Tested by

no test coverage detected