# Class: RetroFont

## Phaser. RetroFont

Phaser.RetroFont

#### new RetroFont(game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset)

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `game` | Phaser.Game |  |  | Current game instance.
  `key` | string |  |  | The font set graphic set as stored in the Game.Cache.
  `characterWidth` | number |  |  | The width of each character in the font set.
  `characterHeight` | number |  |  | The height of each character in the font set.
  `chars` | string |  |  | The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
  `charsPerRow` | number |  |  | The number of characters per row in the font set.
  `xSpacing` | number | <optional> | 0 | If the characters in the font set have horizontal spacing between them set the required amount here.
  `ySpacing` | number | <optional> | 0 | If the characters in the font set have vertical spacing between them set the required amount here.
  `xOffset` | number | <optional> | 0 | If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
  `yOffset` | number | <optional> | 0 | If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.

  Source:
    - gameobjects/RetroFont.js, line 22

### Extends

- Phaser.RenderTexture

### Members

#### <static, constant> ALIGN_CENTER :string

  Align each line of multi-line text in the center.

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 182

#### <static, constant> ALIGN_LEFT :string

  Align each line of multi-line text to the left.

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 168

#### <static, constant> ALIGN_RIGHT :string

  Align each line of multi-line text to the right.

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 175

#### <static, constant> TEXT_SET1 :string

  Text Set 1 = !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 189

#### <static, constant> TEXT_SET2 :string

  Text Set 2 = !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 196

#### <static, constant> TEXT_SET3 :string

  Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 203

#### <static, constant> TEXT_SET4 :string

  Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 210

#### <static, constant> TEXT_SET5 :string

  Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 217

#### <static, constant> TEXT_SET6 :string

  Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789\"(),-.'

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 224

#### <static, constant> TEXT_SET7 :string

  Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW\")28FLRX-'39

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 231

#### <static, constant> TEXT_SET8 :string

  Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 238

#### <static, constant> TEXT_SET9 :string

  Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'\"?!

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 245

#### <static, constant> TEXT_SET10 :string

  Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 252

#### <static, constant> TEXT_SET11 :string

  Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\"-+!?()':;0123456789

  ##### Type:

  - string
  Source:
    - gameobjects/RetroFont.js, line 259

#### align

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `align` | string | Alignment of the text when multiLine = true or a fixedWidth is set. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER.

  Source:
    - gameobjects/RetroFont.js, line 62

#### autoUpperCase

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `autoUpperCase` | boolean | Automatically convert any text to upper case. Lots of old bitmap fonts only contain upper-case characters, so the default is true.

  Default Value:
    - true
  Source:
    - gameobjects/RetroFont.js, line 74

#### characterHeight

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `characterHeight` | number | The height of each character in the font set.

  Source:
    - gameobjects/RetroFont.js, line 32

#### characterPerRow

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `characterPerRow` | number | The number of characters per row in the font set.

  Source:
    - gameobjects/RetroFont.js, line 47

#### characterSpacingX

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `characterSpacingX` | number | If the characters in the font set have horizontal spacing between them set the required amount here.

  Source:
    - gameobjects/RetroFont.js, line 37

#### characterSpacingY

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `characterSpacingY` | number | If the characters in the font set have vertical spacing between them set the required amount here.

  Source:
    - gameobjects/RetroFont.js, line 42

#### characterWidth

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `characterWidth` | number | The width of each character in the font set.

  Source:
    - gameobjects/RetroFont.js, line 27

#### customSpacingX

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `customSpacingX` | number | Adds horizontal spacing between each character of the font, in pixels.

  Default Value:
    - 0
  Source:
    - gameobjects/RetroFont.js, line 80

#### customSpacingY

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `customSpacingY` | number | Adds vertical spacing between each line of multi-line text, set in pixels.

  Default Value:
    - 0
  Source:
    - gameobjects/RetroFont.js, line 86

#### fixedWidth

  If you need this RetroFont image to have a fixed width you can set the width in this value. If text is wider than the width specified it will be cropped off.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `fixedWidth` | number |

  Source:
    - gameobjects/RetroFont.js, line 93

#### fontSet

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `fontSet` | HTMLImage | A reference to the image stored in the Game.Cache that contains the font.

  Source:
    - gameobjects/RetroFont.js, line 98

#### game

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | A reference to the currently running game.

  Inherited From:
    - Phaser.RenderTexture#game
  Source:
    - gameobjects/RenderTexture.js, line 26

#### key

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `key` | string | The key of the RenderTexture in the Cache, if stored there.

  Inherited From:
    - Phaser.RenderTexture#key
  Source:
    - gameobjects/RenderTexture.js, line 31

#### multiLine

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `multiLine` | boolean | If set to true all carriage-returns in text will form new lines (see align). If false the font will only contain one single line of text (the default)

  Default Value:
    - false
  Source:
    - gameobjects/RetroFont.js, line 68

#### offsetX

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `offsetX` | number | If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.

  Source:
    - gameobjects/RetroFont.js, line 52

#### offsetY

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `offsetY` | number | If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.

  Source:
    - gameobjects/RetroFont.js, line 57

#### type

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `type` | number | Base Phaser object type.

  Source:
    - gameobjects/RetroFont.js, line 156

### Methods

#### buildRetroFontText()

  Updates the BitmapData of the Sprite with the text

  Source:
    - gameobjects/RetroFont.js, line 314

#### buildRetroFontText(line, x, y, customSpacingX)

  Internal function that takes a single line of text (2nd parameter) and pastes it into the BitmapData at the given coordinates. Used by getLine and getMultiLine

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `line` | string | The single line of text to paste.
  `x` | number | The x coordinate.
  `y` | number | The y coordinate.
  `customSpacingX` | number | Custom X spacing.

  Source:
    - gameobjects/RetroFont.js, line 405

#### getLongestLine() → {number}

  Works out the longest line of text in _text and returns its length

  Source:
    - gameobjects/RetroFont.js, line 447

  ##### Returns:

  The length of the longest line of text.

  Type
    number

#### <protected> removeUnsupportedCharacters(stripCR) → {string}

  Internal helper function that removes all unsupported characters from the _text String, leaving only characters contained in the font set.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `stripCR` | boolean | <optional> | true | Should it strip carriage returns as well?

  Source:
    - gameobjects/RetroFont.js, line 474

  ##### Returns:

  A clean version of the string.

  Type
    string

#### render(displayObject, position, clear)

  This function will draw the display object to the texture.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `displayObject` | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Group | The display object to render to this texture.
  `position` | Phaser.Point | A Point object containing the position to render the display object at.
  `clear` | boolean | If true the texture will be cleared before the display object is drawn.

  Inherited From:
    - Phaser.RenderTexture#render
  Source:
    - gameobjects/RenderTexture.js, line 70

#### renderXY(displayObject, x, y, clear)

  This function will draw the display object to the texture.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `displayObject` | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Group | The display object to render to this texture.
  `x` | number | The x position to render the object at.
  `y` | number | The y position to render the object at.
  `clear` | boolean | If true the texture will be cleared before the display object is drawn.

  Inherited From:
    - Phaser.RenderTexture#renderXY
  Source:
    - gameobjects/RenderTexture.js, line 51

#### resize(width, height)

  Resize this RenderTexture to the given width and height.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `width` | number | The new width of the RenderTexture.
  `height` | number | The new height of the RenderTexture.

  Inherited From:
    - Phaser.RenderTexture#resize
  Source:
    - gameobjects/RenderTexture.js, line 72

#### setFixedWidth(width, lineAlignment)

  If you need this FlxSprite to have a fixed width and custom alignment you can set the width here.<br> If text is wider than the width specified it will be cropped off.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `width` | number |  |  | Width in pixels of this RetroFont. Set to zero to disable and re-enable automatic resizing.
  `lineAlignment` | string | <optional> | 'left' | Align the text within this width. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER.

  Source:
    - gameobjects/RetroFont.js, line 261

#### setText(content, multiLine, characterSpacing, lineSpacing, lineAlignment, allowLowerCase)

  A helper function that quickly sets lots of variables at once, and then updates the text.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `content` | string |  |  | The text of this sprite.
  `multiLine` | boolean | <optional> | false | Set to true if you want to support carriage-returns in the text and create a multi-line sprite instead of a single line.
  `characterSpacing` | number | <optional> | 0 | To add horizontal spacing between each character specify the amount in pixels.
  `lineSpacing` | number | <optional> | 0 | To add vertical spacing between each line of text, set the amount in pixels.
  `lineAlignment` | string | <optional> | 'left' | Align each line of multi-line text. Set to RetroFont.ALIGN_LEFT, RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER.
  `allowLowerCase` | boolean | <optional> | false | Lots of bitmap font sets only include upper-case characters, if yours needs to support lower case then set this to true.

  Source:
    - gameobjects/RetroFont.js, line 279