* @param {number} x - position of the text object * @param {number} y - position of the text object * @param {object} settings - the text configuration * @param {string|Image} settings.font - a font name to identify the corresponing source image * @param {string} [settings.fontData=settings.
(x, y, settings)
| 40 | * app.world.addChild(myFont); |
| 41 | */ |
| 42 | constructor(x, y, settings) { |
| 43 | // call the parent constructor |
| 44 | super(x, y, settings.width || 0, settings.height || 0); |
| 45 | |
| 46 | /** |
| 47 | * Set the default text alignment (or justification),<br> |
| 48 | * possible values are "left", "right", and "center". |
| 49 | * @public |
| 50 | * @type {string} |
| 51 | * @default "left" |
| 52 | */ |
| 53 | this.textAlign = settings.textAlign || "left"; |
| 54 | |
| 55 | /** |
| 56 | * Set the text baseline (e.g. the Y-coordinate for the draw operation), <br> |
| 57 | * possible values are "top", "hanging", "middle", "alphabetic", "ideographic", "bottom"<br> |
| 58 | * @public |
| 59 | * @type {string} |
| 60 | * @default "top" |
| 61 | */ |
| 62 | this.textBaseline = settings.textBaseline || "top"; |
| 63 | |
| 64 | /** |
| 65 | * Set the line spacing height (when displaying multi-line strings). <br> |
| 66 | * Current font height will be multiplied with this value to set the line height. |
| 67 | * @public |
| 68 | * @type {number} |
| 69 | * @default 1.0 |
| 70 | */ |
| 71 | this.lineHeight = settings.lineHeight || 1.0; |
| 72 | |
| 73 | /** |
| 74 | * the maximum length in CSS pixel for a single segment of text. |
| 75 | * (use -1 to disable word wrapping) |
| 76 | * @public |
| 77 | * @type {number} |
| 78 | * @default -1 |
| 79 | */ |
| 80 | this.wordWrapWidth = settings.wordWrapWidth || -1; |
| 81 | |
| 82 | /** |
| 83 | * the text to be displayed |
| 84 | * @private |
| 85 | */ |
| 86 | this._text = []; |
| 87 | |
| 88 | /** |
| 89 | * scaled font size |
| 90 | * @private |
| 91 | */ |
| 92 | this.fontScale = vector2dPool.get(1.0, 1.0); |
| 93 | |
| 94 | /** |
| 95 | * font image |
| 96 | * @private |
| 97 | */ |
| 98 | this.fontImage = |
| 99 | typeof settings.font === "object" |