Class: BitmapText

PIXI~BitmapText

A BitmapText object will create a line or multiple lines of text using bitmap font.

The primary advantage of this class over Text is that all of your textures are pre-generated and loading, meaning that rendering is fast, and changing text has no performance implications.

The primary disadvantage is that you need to preload the bitmap font assets, and thus the styling is set in stone. Supporting character sets other than latin, such as CJK languages, may be impractical due to the number of characters.

To split a line you can use '\n', '\r' or '\r\n' in your string.

You can generate the fnt files using http://www.angelcode.com/products/bmfont/ for Windows or http://www.bmglyph.com/ for Mac.

A BitmapText can only be created when the font is loaded.

// in this case the font is in a file called 'desyrel.fnt'
let bitmapText = new PIXI.BitmapText("text using a fancy font!", {font: "35px Desyrel", align: "right"});

new BitmapText (text, style)

Name Type Description
text string

A string that you would like the text to display.

style object

The style parameters.

Name Type Default Description
font string | object

The font descriptor for the object, can be passed as a string of form "24px FontName" or "FontName" or as an object with explicit name/size properties.

Name Type Description
name string optional

The bitmap font id.

size number optional

The size of the font in pixels, e.g. 24

align string 'left' optional

Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text.

tint number 0xFFFFFF optional

The tint color.

Extends

Members

_accessibleActive boolean inherited overrides

TODO
  • Needs docs.

_accessibleDiv boolean inherited overrides

TODO
  • Needs docs.

bounds对象,用于计算和存储displayObject的边界。

_boundsID number protected inherited overrides

TODO

_boundsRect PIXI.Bounds protected inherited overrides

TODO

_destroyed boolean protected inherited overrides

如果对象已通过destroy()销毁, 则为true,此属性不应被使用。

_enabledFilters Array.<PIXI.Filter> protected inherited overrides

当前启用的滤镜

_lastSortedIndex number protected inherited overrides

显示组件在子数组中的哪个索引在上一个zIndex排序之前。 由容器使用,通过使用前一个数组索引作为决策器,帮助对具有相同zIndex的对象进行排序。

_localBoundsRect PIXI.Bounds protected inherited overrides

TODO

_mask PIXI.Graphics | PIXI.Sprite | null protected inherited overrides

对象的原始缓存掩罩。

_tempDisplayObjectParent PIXI.Container protected inherited overrides

_zIndex number protected inherited overrides

displayObject的zIndex。 较高的值意味着它将呈现在同一容器中其他显示对象的顶部。

accessible boolean inherited overrides

标记对象是否可访问。 如果为true,AccessibilityManager将使用属性集覆盖阴影div

accessibleChildren boolean inherited overrides

设置为false将阻止访问此容器中的所有子级。 默认为true。

Default Value:
  • true

accessibleHint string inherited overrides

设置阴影div的aria-label属性

accessiblePointerEvents string inherited overrides

指定可访问的div将使用的指针事件 默认为'auto'

Default Value:
  • 'auto'

accessibleTitle string nullable inherited overrides

设置阴影div的title属性。如果尚未设置accessibleTitle和accessibleHint,则默认为 'displayObject [tabIndex]'

accessibleType string inherited overrides

指定可访问层的div的类型。 屏幕阅读器会根据此类型对元素进行不同的处理。 默认为 button.

Default Value:
  • 'button'

align string

The alignment of the BitmapText object.

Default Value:
  • 'left'

alpha number inherited overrides

对象的不透明度。

anchor PIXI.Point | number

The anchor sets the origin point of the text.

The default is (0,0), this means the text's origin is the top left.

Setting the anchor to (0.5,0.5) means the text's origin is centered.

Setting the anchor to (1,1) would mean the text's origin point will be the bottom right corner.

angle number inherited overrides

物体的角度,以度为单位。 'rotation' 和 'angle' 对显示对象具有相同的效果; 旋转单位为弧度,角度单位为度。

buttonMode boolean inherited overrides

如果启用,则鼠标光标悬停在displayObject上时,如果它是交互式的,则使用指针行为 设置此项会将'cursor'属性更改为''pointer'`。

Example
const sprite = new PIXI.Sprite(texture);
sprite.interactive = true;
sprite.buttonMode = true;

cacheAsBitmap boolean inherited overrides

如果希望将此显示对象缓存为位图,请将其设置为true。 这基本上是对显示对象的快照。它可以为复杂的静态displayObjects提供性能优势。 要删除,只需将此属性设置为false即可。

重要提示-在将此属性设置为true之前,请确保已预加载所有纹理,因为它将获取当前纹理的快照。 如果尚未加载纹理,则它们将不会显示。

children Array.<PIXI.DisplayObject> readonly inherited overrides

此容器的子级数组。

cursor string inherited overrides

定义鼠标光标时使用的光标模式悬停在displayObject上。

See:
Example
const sprite = new PIXI.Sprite(texture);
sprite.interactive = true;
sprite.cursor = 'wait';

dirty boolean

The dirty state of this object.

filterArea PIXI.Rectangle nullable inherited overrides

设置滤镜的区域。这更多的是用作优化,而不是计算可以设置此矩形的每个帧的displayObject的尺寸。

也可用作交互掩罩。

filters Array.<PIXI.Filter> nullable inherited overrides

设置displayObject的滤镜。

  • 重要提示:这是一个WebGL独有的功能,将被画布渲染器忽略。 若要删除滤镜,只需将此属性设置为'null'

font object

The font descriptor of the BitmapText object.

height number inherited overrides

容器的高度,设置此高度实际上会修改比例,以达到设置的值

元素可点击范围 互动形状。首先将命中子集,然后再检查此形状。 设置此项将导致在命中测试中将使用此范围,而不是显示对象的边界范围。

Example
const sprite = new PIXI.Sprite(texture);
sprite.interactive = true;
sprite.hitArea = new PIXI.Rectangle(0, 0, 100, 100);

interactive boolean inherited overrides

启用DisplayObject的交互事件。如果不将interactive设置为true,则不会触发触摸,指针和鼠标事件。

Example
const sprite = new PIXI.Sprite(texture);
sprite.interactive = true;
sprite.on('tap', (event) => {
   //处理事件
});

interactiveChildren boolean inherited overrides

确定是否可以触发displayObject的子节点的clicked/touched 设置为false将允许PixiJS绕过递归的hitTest函数

isMask boolean inherited overrides

是否还有其他displayObject将此对象用作遮罩?

isSprite boolean inherited overrides

用于快速检查精灵是否是.. 一个精灵!

letterSpacing number

Additional space between characters.

localTransform PIXI.Matrix readonly inherited overrides

基于局部因素的当前对象变换:位置、比例、其他内容。

设置displayObject的遮罩。遮罩是将对象的可见性限制为应用于其的遮罩形状的对象。 在PixiJS中,常规遮罩必须是PIXI.GraphicsPIXI.Sprite对象。 PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it 这样可以在画布中更快地进行遮罩,因为它实用程序形状剪辑。若要删除掩码,请将此属性设置为null

对于精灵遮罩,使用alpha和red通道。黑色遮罩与透明遮罩相同。

TODO
  • 目前,PIXI.CanvasRenderer不支持PIXI.Sprite作为遮罩。
Example
const graphics = new PIXI.Graphics();
graphics.beginFill(0xFF3300);
graphics.drawRect(50, 250, 100, 100);
graphics.endFill();

const sprite = new PIXI.Sprite(texture);
sprite.mask = graphics;

maxLineHeight number readonly

The max line height. This is useful when trying to use the total height of the Text, i.e. when trying to vertically align.

maxWidth number

The max width of this bitmap text in pixels. If the text provided is longer than the value provided, line breaks will be automatically inserted in the last whitespace. Disable by setting the value to 0.

name string inherited overrides

The instance name of the object.

包含此显示对象的显示对象容器。

显示对象绕其旋转的轴心点。 pixi-v4开始按值传递。

对象相对于父对象的局部坐标的坐标。 pixi-v4开始按值传递。

renderable boolean inherited overrides

是否可以渲染此对象,如果为false,则不会绘制对象,但仍将调用updateTransform方法。

仅影响来自父级的递归调用。 您可以手动请求边界。

rotation number inherited overrides

物体的弧度旋转。 'rotation' 和 'angle' 对显示对象具有相同的效果; 旋转单位为弧度,角度单位为度。

roundPixels boolean

如果为true,则在渲染时,PixiJS将使用Math.floor() x/y值,从而停止像素插值。 优点包括更清晰的图像质量(如文本)和在canvas上更快的渲染。 主要缺点是物体的运动可能看起来不太平滑。 To set the global default, change PIXI.settings.ROUND_PIXELS

Default Value:
  • false

对象的比例因子。 pixi-v4开始按值传递。

对象的歪斜因子,以弧度为单位。 pixi-v4开始按值传递。

sortableChildren boolean inherited overrides

如果设置为true,则在调用updateTransform()时容器将按zIndex值对其子级进行排序, 或者在调用sortChildren()时手动排序。

这实际上会更改数组中元素的顺序,因此应将其视为与其他解决方案相比性能不佳的基本解决方案, 例如 @link https://github.com/pixijs/pixi-display

还要注意,这可能无法很好地与addChildAt()函数一起工作, 因为zIndex排序可能会导致子项自动排序到另一个位置。

See:

sortDirty boolean inherited overrides

在下一次updateTransform调用时,是否应按zIndex对子级进行排序。 如果添加了新子级或子级的zIndex更改,则将自动设置为true。

text string

The text of the BitmapText object.

textHeight number readonly

The height of the overall text, different from fontSize, which is defined in the style object.

textWidth number readonly

The width of the overall text, different from fontSize, which is defined in the style object.

tint number

The tint of the BitmapText object.

该对象的世界变换和局部变换。 稍后它将变为只读,除非您知道自己在做什么,否则请不要在其中分配任何内容。

visible boolean inherited overrides

对象的可见性。 如果为false,则不会绘制对象,并且不会调用updateTransform函数。

仅影响来自父级的递归调用。 您可以请求边界或手动调用updateTransform。

width number inherited overrides

容器的宽度,设置此值实际上会修改比例,以达到设置的值

worldAlpha number readonly inherited overrides

displayObject的相乘alpha。

worldTransform PIXI.Matrix readonly inherited overrides

基于世界(父)因素的对象的当前变换。

worldVisible boolean readonly inherited overrides

指示对象是否世界可见。

x number inherited overrides

displayObject在x轴上相对于父级本地坐标的位置。 position.x的别名

y number inherited overrides

displayObject在y轴上相对于父级本地坐标的位置 position.y的别名

zIndex number inherited overrides

displayObject的zIndex。 如果容器的sortableChildren属性设置为true,则子容器将按zIndex值自动排序;值越大,则表示它将移向数组的末尾, 并以此渲染在同一容器中的其他displayObjects之上。

Methods

PIXI.BitmapText.registerFont (xml, textures)Object static

Register a bitmap font with data and a texture.

Name Type Description
xml XMLDocument

The XML document data.

textures Object.<string, PIXI.Texture> | PIXI.Texture | Array.<PIXI.Texture>

List of textures for each page. If providing an object, the key is the <page> element's file attribute in the FNT file.

Returns:
Type Description
Object Result font object with font, size, lineHeight and char fields.

_calculateBounds () protected inherited overrides

重新计算对象的边界。重写此项以计算特定对象(不包括子项)的边界。

_recursivePostUpdateTransform () inherited overrides

递归地将所有对象的转换从根更新为此toLocal()的一个内部函数

_render (renderer) protected inherited overrides

被子类覆盖。

Name Type Description
renderer PIXI.Renderer

渲染器

_renderCanvas (renderer) protected inherited overrides

被子类覆盖

Name Type Description
renderer PIXI.CanvasRenderer

渲染器

将一个或多个子项添加到容器中。

可以像这样添加多个项: myContainer.addChild(thingOne, thingTwo, thingThree)

Name Type Description
children PIXI.DisplayObject repeatable

要添加到容器的显示对象(可以为复数个)

Returns:
Type Description
PIXI.DisplayObject 添加的第一个子项。

在指定索引处向容器添加子项。如果索引超出界限,将抛出一个错误

Name Type Description
child PIXI.DisplayObject

要添加的子项

index number

放置子项的索引

Returns:
Type Description
PIXI.DisplayObject 添加的子项。

calculateBounds () inherited overrides

Recalculates the bounds of the container.

删除所有内部引用和侦听器,并从显示列表中删除子项。 调用destroy后不要再使用容器。

Name Type Description
options object | boolean optional

可选参数,布尔值将充当所有选项都已设置为该值的作用

Name Type Default Description
children boolean false optional

如果设置为true,则所有子项也将调用其destroy方法。 'options'将传递给这些调用。

texture boolean false optional

仅在options.children设置为true时,应用用于子精灵 将销毁子精灵的纹理

baseTexture boolean false optional

仅在options.children设置为true时,应用用于子精灵 将销毁子精灵的基础纹理

displayObjectUpdateTransform () inherited overrides

DisplayObject默认为updateTransform,不更新容器的子级。 如果没有父元素,则会崩溃。

以矩形对象的形式获取displayObject的边界。

Name Type Description
skipUpdate boolean optional

设置为true将阻止场景图的变换被更新。这意味着返回的计算可能已经过时, 但会给您带来很好的性能提升。

rect PIXI.Rectangle optional

可选的矩形,用于存储边界计算的结果。

Returns:
Type Description
PIXI.Rectangle 矩形边界区域

返回指定索引处的子级

Name Type Description
index number

查找的子项索引

Returns:
Type Description
PIXI.DisplayObject 给定索引处的子级(如果有)。

Returns the display object in the container.

Name Type Description
name string

Instance name.

Returns:
Type Description
PIXI.DisplayObject The child with the specified name.

getChildIndex (child)number inherited overrides

返回子DisplayObject实例的索引位置

Name Type Description
child PIXI.DisplayObject

要标识的DisplayObject实例

Returns:
Type Description
number 要标识的子显示对象的索引位置

getGlobalPosition (point, skipUpdate)PIXI.Point inherited overrides

Returns the global position of the displayObject. Does not depend on object scale, rotation and pivot.

Name Type Default Description
point PIXI.Point new PIXI.Point() optional

The point to write the global value to.

skipUpdate boolean false optional

Setting to true will stop the transforms of the scene graph from being updated. This means the calculation returned MAY be out of date BUT will give you a nice performance boost.

Returns:
Type Description
PIXI.Point The updated point.

Validates text before calling parent's getLocalBounds

Returns:
Type Description
PIXI.Rectangle The rectangular bounding area

onChildrenChange () protected inherited overrides

可重写的方法,每当修改子数组时,容器子类都可以使用该方法

从容器中取出一个或多个子项。

Name Type Description
children PIXI.DisplayObject repeatable

要删除的DisplayObject(可以为复数个)

Returns:
Type Description
PIXI.DisplayObject 被删除的第一个子项目。

从指定的索引位置删除子项。

Name Type Description
index number

要删除的子项索引

Returns:
Type Description
PIXI.DisplayObject 被删除的子项。

removeChildren (beginIndex, endIndex)Array.<PIXI.DisplayObject> inherited overrides

从此容器中删除在开始索引和结束索引内的所有子项。

Name Type Default Description
beginIndex number 0 optional

起始位置。

endIndex number this.children.length optional

结束位置。 默认值是容器的大小。

Returns:
Type Description
Array.<PIXI.DisplayObject> 被删除的子项列表

使用WebGL渲染器渲染对象

Name Type Description
renderer PIXI.Renderer

渲染器

renderAdvanced (renderer) protected inherited overrides

使用WebGL渲染器和高级功能渲染对象。

Name Type Description
renderer PIXI.Renderer

渲染器

renderAdvancedWebGL (renderer) Deprecated : since 5.0.0 inherited overrides

Name Type Description
renderer PIXI.Renderer

Instance of renderer

See:

renderCanvas (renderer) inherited overrides

使用Canvas渲染器渲染对象

Name Type Description
renderer PIXI.CanvasRenderer

渲染器

renderWebGL (renderer) Deprecated : since 5.0.0 inherited overrides

Name Type Description
renderer PIXI.Renderer

Instance of renderer

See:

setChildIndex (child, index) inherited overrides

更改现有子项在显示对象容器中的位置

Name Type Description
child PIXI.DisplayObject

要为其更改索引号的子DisplayObject实例

index number

子显示对象的结果索引

设置此DisplayObject的父容器。

Name Type Description
container PIXI.Container

要将此DisplayObject添加到的容器。

Returns:
Type Description
PIXI.Container 此DisplayObject添加到的容器。

setTransform (x, y, scaleX, scaleY, rotation, skewX, skewY, pivotX, pivotY)PIXI.DisplayObject inherited overrides

便捷方法,可同时设置位置,比例,倾斜和枢轴。

Name Type Default Description
x number 0 optional

X位置

y number 0 optional

Y位置

scaleX number 1 optional

X标度值

scaleY number 1 optional

Y标度值

rotation number 0 optional

旋转

skewX number 0 optional

X偏斜值

skewY number 0 optional

Y偏斜值

pivotX number 0 optional

X轴值

pivotY number 0 optional

Y轴值

Returns:
Type Description
PIXI.DisplayObject DisplayObject实例

按zIndex对子项进行排序。对于具有相同zIndex的2个子项,将维持先前的顺序。

swapChildren (child, child2) inherited overrides

交换此容器中两个显示对象的位置。

Name Type Description
child PIXI.DisplayObject

要交换的第一个显示对象

child2 PIXI.DisplayObject

要交换的第二个显示对象

toGlobal (position, point, skipUpdate)PIXI.Point inherited overrides

计算显示对象的世界位置。

Name Type Default Description
position PIXI.IPoint

要计算的世界原点。

point PIXI.Point optional

存储值的Point对象,可选 (为空时,会创建一个新的Point).

skipUpdate boolean false optional

是否跳过更新转换

Returns:
Type Description
PIXI.Point 表示此对象位置的Point对象。

toLocal (position, from, point, skipUpdate)PIXI.Point inherited overrides

计算显示对象相对于另一点的局部位置。

Name Type Default Description
position PIXI.IPoint

要计算的世界原点。

from PIXI.DisplayObject optional

从中计算世界位置的DisplayObject。

point PIXI.Point optional

存储值的Point对象,可选 (为空时,会创建一个新的Point).

skipUpdate boolean false optional

是否跳过更新转换

Returns:
Type Description
PIXI.Point 表示此对象位置的Point对象

Events

将此DisplayObject添加到容器时触发。

Name Type Description
container PIXI.Container

添加到的容器。

Fired when a pointer device button (usually a mouse left-button) is pressed and released on the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device button (usually a mouse left-button) is pressed on the display. object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device (usually a mouse) is moved while over the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device (usually a mouse) is moved off the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device (usually a mouse) is moved onto the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device button (usually a mouse left-button) is released over the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device button (usually a mouse left-button) is released outside the display object that initially registered a mousedown. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when the operating system cancels a pointer event. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device button is pressed on the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device is moved while over the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device is moved off the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device is moved onto the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device button is pressed and released on the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device button is released over the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device button is released outside the display object that initially registered a pointerdown. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

从容器中移除此DisplayObject时触发。

Name Type Description
container PIXI.Container

从中移除的容器。

Fired when a pointer device secondary button (usually a mouse right-button) is pressed and released on the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device secondary button (usually a mouse right-button) is pressed on the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device secondary button (usually a mouse right-button) is released over the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a pointer device secondary button (usually a mouse right-button) is released outside the display object that initially registered a rightdown. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a touch point is placed and removed from the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when the operating system cancels a touch. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a touch point is removed from the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a touch point is removed outside of the display object that initially registered a touchstart. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a touch point is moved along the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event

Fired when a touch point is placed on the display object. DisplayObject's interactive property must be set to true to fire event.

Name Type Description
event PIXI.interaction.InteractionEvent

Interaction event