GabLeRoux

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. Just posting that typescript snippet again, but with proper line ending 😕 export function setText(field: Phaser.Text, text: string, width?: number, height?: number) { // So we don't lose the original value of the font size, create a property on the field to store it. if (!('defaultFontSize' in field)) { field['defaultFontSize'] = field.fontSize; } // Set the field's font size back to it's original value before setting the new text. field.fontSize = field['defaultFontSize']; // If word wrap is set, then use the word wrap width as the bounds' width instead. if (field.wordWrap) { width = field.wordWrapWidth; } // Set the field's text property. field.text = text; // Check if bounds were provided. if (width > 0 && height > 0) { // Use the default font size as a base for the auto sizing. var size: number = field['defaultFontSize']; // While the width or height is greater then the provided bounds, subtract one from the font size. while ((field.width > width || field.height > height) && field.fontSize > 4) { field.fontSize = --size; } } } Didn't try it, but I'm a simple human and reading code is easier when it's not on a single line.