Pixi.js: BitmapText width after text change

Created on 22 Sep 2020  ·  3Comments  ·  Source: pixijs/pixi.js

Expected Behavior

Current Behavior

Create a PIXI.BitmapText instance with this text "1111111111111111111111111". Remember its width, then change the text to "1" and check the width again, it will be the same.

Possible Solution

This problem exists when PIXI.BitmapText instance has PIXI.Mesh instance as children with more than 199 vertices

Steps to Reproduce

https://pixijs.io/examples/#/text/bitmap-text.js
Paste this code:

const app = new PIXI.Application({ backgroundColor: 0x1099bb });
document.body.appendChild(app.view);

app.loader
    .add('desyrel', 'examples/assets/bitmap-font/desyrel.xml')
    .load(onAssetsLoaded);

function onAssetsLoaded() {
    const bitmapFontText = new PIXI.BitmapText('11111111111111111111111111111111111111111111111', { font: '55px Desyrel'});
    console.log(bitmapFontText.width);
    bitmapFontText.x = 50;
    bitmapFontText.y = 200;
    bitmapFontText.text = '1';
    console.log(bitmapFontText.width);
    app.stage.addChild(bitmapFontText);
}

Environment

  • pixi.js version: 5.3.2
  • Browser & Version: Chrome 85
  • OS & Version: Windows 10
🕷 Bug

Most helpful comment

Here's a JSFiddle version:
https://jsfiddle.net/bigtimebuddy/syt6gdpb/

As I understand, this problem arises because we don't clean vertices buffer when new text smaller than previous.
Check how this condition works
image

All 3 comments

Here's a JSFiddle version:
https://jsfiddle.net/bigtimebuddy/syt6gdpb/

Here's a JSFiddle version:
https://jsfiddle.net/bigtimebuddy/syt6gdpb/

As I understand, this problem arises because we don't clean vertices buffer when new text smaller than previous.
Check how this condition works
image

Probably zeroing out the vertex buffer would fix this problem, if it not newly created.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Darker picture Darker  ·  3Comments

distinctdan picture distinctdan  ·  3Comments

readygosports picture readygosports  ·  3Comments

Makio64 picture Makio64  ·  3Comments

samueller picture samueller  ·  3Comments