Class: BitmapFont
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/BitmapFont.d.ts:118
A BitmapFont object represents a particular font face, size, and style. This class handles both pre-loaded bitmap fonts and dynamically generated ones.
Example
import { BitmapFont, Texture } from 'pixi.js';
// Create a bitmap font from loaded textures and data
const font = new BitmapFont({
data: {
pages: [{ id: 0, file: 'font.png' }],
chars: {
'A': {
id: 65,
page: 0,
x: 0,
y: 0,
width: 32,
height: 32,
xOffset: 0,
yOffset: 0,
xAdvance: 32,
letter: 'A'
}
},
fontSize: 32,
lineHeight: 36,
baseLineOffset: 26,
fontFamily: 'MyFont',
distanceField: {
type: 'msdf',
range: 4
}
},
textures: [Texture.from('font.png')]
});
// Install a font for global use
BitmapFont.install({
name: 'MyCustomFont',
style: {
fontFamily: 'Arial',
fontSize: 32,
fill: '#ffffff',
stroke: { color: '#000000', width: 2 }
}
});
// Uninstall when no longer needed
BitmapFont.uninstall('MyCustomFont');
Standard
Extends
AbstractBitmapFont<BitmapFont>
Constructors
Constructor
> new BitmapFont(options, url?): BitmapFont
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/BitmapFont.d.ts:128
Parameters
options
url?
string
Returns
BitmapFont
Overrides
AbstractBitmapFont.constructor
Properties
applyFillAsTint
> applyFillAsTint: boolean
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:107
should the fill for this font be applied as a tint to the text.
Inherited from
AbstractBitmapFont.applyFillAsTint
baseLineOffset
> readonly baseLineOffset: number
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:99
The offset of the font face from the baseline.
Inherited from
AbstractBitmapFont.baseLineOffset
baseMeasurementFontSize
> readonly baseMeasurementFontSize: number
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:109
The size of the font face in pixels.
Inherited from
AbstractBitmapFont.baseMeasurementFontSize
baseRenderedFontSize
> protected baseRenderedFontSize: number
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:110
Inherited from
AbstractBitmapFont.baseRenderedFontSize
chars
> readonly chars: Record<string, CharData>
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:82
The map of characters by character string.
Inherited from
distanceField
> readonly distanceField: { range: number; type: "none" | "sdf" | "msdf"; } | undefined
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:101
The range and type of the distance field for this font.
Union Members
Type Literal
{ range: number; type: "none" | "sdf" | "msdf"; }
range
> range: number
Range of the distance field in pixels
type
> type: "none" | "sdf" | "msdf"
Type of distance field
undefined
Inherited from
AbstractBitmapFont.distanceField
fontFamily
> readonly fontFamily: string
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:92
The name of the font face
Inherited from
fontMetrics
> readonly fontMetrics: FontMetrics
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:94
The metrics of the font face.
Inherited from
AbstractBitmapFont.fontMetrics
lineHeight
> readonly lineHeight: number
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:87
The line-height of the font face in pixels.
Inherited from
pages
> readonly pages: object[]
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:103
The map of base page textures (i.e., sheets of glyphs).
texture
> texture: Texture
Inherited from
url?
> optional url?: string
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/BitmapFont.d.ts:127
The URL from which the font was loaded, if applicable. This is useful for tracking font sources and reloading.
Example
console.log(font.url); // 'fonts/myFont.fnt'
prefixed
> static prefixed: string | boolean
Defined in: node_modules/eventemitter3/index.d.ts:9
Inherited from
Accessors
distanceFieldRange
Get Signature
> get distanceFieldRange(): number
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:130
The kind of distance field for this font or "none".
Deprecated
since 8.0.0 Use distanceField.type instead.
Returns
number
Inherited from
AbstractBitmapFont.distanceFieldRange
distanceFieldType
Get Signature
> get distanceFieldType(): "none" | "sdf" | "msdf"
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:135
The range of the distance field in pixels.
Deprecated
since 8.0.0 Use distanceField.range instead.
Returns
"none" | "sdf" | "msdf"
Inherited from
AbstractBitmapFont.distanceFieldType
font
Get Signature
> get font(): string
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:115
The name of the font face.
Deprecated
since 8.0.0 Use fontFamily instead.
Returns
string
Inherited from
pageTextures
Get Signature
> get pageTextures(): object[]
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:120
The map of base page textures (i.e., sheets of glyphs).
Deprecated
since 8.0.0 Use pages instead.
Returns
object[]
Inherited from
AbstractBitmapFont.pageTextures
size
Get Signature
> get size(): number
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.d.ts:125
The size of the font face in pixels.
Deprecated
since 8.0.0 Use fontMetrics.fontSize instead.
Returns
number
Inherited from
Methods
addListener()
> addListener<T>(event, fn, context?): this
Defined in: node_modules/eventemitter3/index.d.ts:45
Type Parameters
T
T extends "destroy"
Parameters
event
T
fn
(...args) => void
context?
any
Returns
this
Inherited from
AbstractBitmapFont.addListener
destroy()
> destroy(): void
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/BitmapFont.d.ts:130
Destroys the BitmapFont object.
Returns
void
Overrides
emit()
> emit<T>(event, ...args): boolean
Defined in: node_modules/eventemitter3/index.d.ts:32
Calls each of the listeners registered for a given event.
Type Parameters
T
T extends "destroy"
Parameters
event
T
args
...ArgumentMap<BitmapFontEvents<BitmapFont>>[Extract<T, "destroy">]
Returns
boolean
Inherited from
AbstractBitmapFont.emit
eventNames()
> eventNames(): "destroy"[]
Defined in: node_modules/eventemitter3/index.d.ts:15
Return an array listing the events for which the emitter has registered listeners.
Returns
"destroy"[]
Inherited from
AbstractBitmapFont.eventNames
listenerCount()
> listenerCount(event): number
Defined in: node_modules/eventemitter3/index.d.ts:27
Return the number of listeners listening to a given event.
Parameters
event
"destroy"
Returns
number
Inherited from
AbstractBitmapFont.listenerCount
listeners()
> listeners<T>(event): (...args) => void[]
Defined in: node_modules/eventemitter3/index.d.ts:20
Return the listeners registered for a given event.
Type Parameters
T
T extends "destroy"
Parameters
event
T
Returns
(...args) => void[]
Inherited from
AbstractBitmapFont.listeners
off()
> off<T>(event, fn?, context?, once?): this
Defined in: node_modules/eventemitter3/index.d.ts:69
Type Parameters
T
T extends "destroy"
Parameters
event
T
fn?
(...args) => void
context?
any
once?
boolean
Returns
this
Inherited from
AbstractBitmapFont.off
on()
> on<T>(event, fn, context?): this
Defined in: node_modules/eventemitter3/index.d.ts:40
Add a listener for a given event.
Type Parameters
T
T extends "destroy"
Parameters
event
T
fn
(...args) => void
context?
any
Returns
this
Inherited from
AbstractBitmapFont.on
once()
> once<T>(event, fn, context?): this
Defined in: node_modules/eventemitter3/index.d.ts:54
Add a one-time listener for a given event.
Type Parameters
T
T extends "destroy"
Parameters
event
T
fn
(...args) => void
context?
any
Returns
this
Inherited from
AbstractBitmapFont.once
removeAllListeners()
> removeAllListeners(event?): this
Defined in: node_modules/eventemitter3/index.d.ts:79
Remove all listeners, or those of the specified event.
Parameters
event?
"destroy"
Returns
this
Inherited from
AbstractBitmapFont.removeAllListeners
removeListener()
> removeListener<T>(event, fn?, context?, once?): this
Defined in: node_modules/eventemitter3/index.d.ts:63
Remove the listeners of a given event.
Type Parameters
T
T extends "destroy"
Parameters
event
T
fn?
(...args) => void
context?
any
once?
boolean
Returns
this
Inherited from
AbstractBitmapFont.removeListener
install()
> static install(options): void
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/BitmapFont.d.ts:166
Generates and installs a bitmap font with the specified options. The font will be cached and available for use in BitmapText objects.
Parameters
options
Setup options for font generation
Returns
void
Installed font instance
Example
// Install a basic font
BitmapFont.install({
name: 'Title',
style: {
fontFamily: 'Arial',
fontSize: 32,
fill: '#ffffff'
}
});
// Install with advanced options
BitmapFont.install({
name: 'Custom',
style: {
fontFamily: 'Arial',
fontSize: 24,
fill: '#00ff00',
stroke: { color: '#000000', width: 2 }
},
chars: [['a', 'z'], ['A', 'Z'], ['0', '9']],
resolution: 2,
padding: 4,
textureStyle: {
scaleMode: 'nearest'
}
});
uninstall()
> static uninstall(name): void
Defined in: node_modules/pixi.js/lib/scene/text-bitmap/BitmapFont.d.ts:180
Uninstalls a bitmap font from the cache. This frees up memory and resources associated with the font.
Parameters
name
string
The name of the bitmap font to uninstall
Returns
void
Example
// Remove a font when it's no longer needed
BitmapFont.uninstall('MyCustomFont');
// Clear multiple fonts
['Title', 'Heading', 'Body'].forEach(BitmapFont.uninstall);