Shaku

Shaku JS

Back To Table of Content

Font Texture Asset

Classes

FontTextureAsset

A font texture asset, dynamically generated from loaded font and canvas. This asset type creates an atlas of all the font's characters as textures, so we can later render them as sprites.

Functions

measureTextHeight()

Measure font's actual height.

measureTextWidth()

Measure font's actual width.

FontTextureAsset

A font texture asset, dynamically generated from loaded font and canvas. This asset type creates an atlas of all the font’s characters as textures, so we can later render them as sprites.

Kind: global class

fontTextureAsset.lineHeight

Get line height.

Kind: instance property of FontTextureAsset

fontTextureAsset.fontName

Get font name.

Kind: instance property of FontTextureAsset

fontTextureAsset.fontSize

Get font size.

Kind: instance property of FontTextureAsset

fontTextureAsset.placeholderCharacter

Get placeholder character.

Kind: instance property of FontTextureAsset

fontTextureAsset.texture

Get the texture.

Kind: instance property of FontTextureAsset

fontTextureAsset.width ⇒ Number

Get texture width.

Kind: instance property of FontTextureAsset
Returns: Number - Texture width.

fontTextureAsset.height ⇒ Number

Get texture height.

Kind: instance property of FontTextureAsset
Returns: Number - Texture height.

fontTextureAsset.valid

Kind: instance property of FontTextureAsset

fontTextureAsset.load(params) ⇒ Promise

Generate the font texture from a font found in given URL.

Kind: instance method of FontTextureAsset
Returns: Promise - Promise to resolve when fully loaded.

Param Type Description
params \* Additional params. Possible values are: - fontName: mandatory font name. on some browsers if the font name does not match the font you actually load via the URL, it will not be loaded properly. - missingCharPlaceholder (default=’?’): character to use for missing characters. - smoothFont (default=true): if true, will set font to smooth mode. - fontSize (default=52): font size in texture. larget font size will take more memory, but allow for sharper text rendering in larger scales. - enforceTexturePowerOfTwo (default=true): if true, will force texture size to be power of two. - maxTextureWidth (default=1024): max texture width. - charactersSet (default=FontTextureAsset.defaultCharactersSet): which characters to set in the texture. - extraPadding (default=0,0): Optional extra padding to add around characters in texture. - sourceRectOffsetAdjustment (default=0,0): Optional extra offset in characters source rectangles. Use this for fonts that are too low / height and bleed into other characters source rectangles.

fontTextureAsset.getSize() ⇒ Vector2

Get texture size as a vector.

Kind: instance method of FontTextureAsset
Returns: Vector2 - Texture size.

fontTextureAsset.getSourceRect(character) ⇒ Rectangle

Get the source rectangle for a given character in texture.

Kind: instance method of FontTextureAsset
Returns: Rectangle - Source rectangle for character.

Param Type Description
character Character Character to get source rect for.

fontTextureAsset.getPositionOffset(character) ⇒ Vector2

When drawing the character, get the offset to add to the cursor.

Kind: instance method of FontTextureAsset
Returns: Vector2 - Offset to add to the cursor before drawing the character.

Param Type Description
character Character Character to get the offset for.

fontTextureAsset.getXAdvance(character) ⇒ Number

Get how much to advance the cursor when drawing this character.

Kind: instance method of FontTextureAsset
Returns: Number - Distance to move the cursor after drawing the character.

Param Type Description
character Character Character to get the advance for.

fontTextureAsset.destroy()

Kind: instance method of FontTextureAsset

measureTextHeight()

Measure font’s actual height.

Kind: global function

measureTextWidth()

Measure font’s actual width.

Kind: global function