Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitmapText width after text change #6900

Closed
Vardner opened this issue Sep 22, 2020 · 3 comments · Fixed by #6902
Closed

BitmapText width after text change #6900

Vardner opened this issue Sep 22, 2020 · 3 comments · Fixed by #6902
Labels
🕷 Bug Verified that it’s actually a legit bug that exists in the current release.

Comments

@Vardner
Copy link

Vardner commented Sep 22, 2020

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
@bigtimebuddy
Copy link
Member

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

@bigtimebuddy bigtimebuddy added the 🕷 Bug Verified that it’s actually a legit bug that exists in the current release. label Sep 22, 2020
@Vardner
Copy link
Author

Vardner commented Sep 22, 2020

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

@ShukantPal
Copy link
Member

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

ShukantPal added a commit that referenced this issue Sep 23, 2020
This will fix issues with bounds calculations like #6900.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕷 Bug Verified that it’s actually a legit bug that exists in the current release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants