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

Feature-Request: V8 support sub-Textures when creating BitmapFont objects #10482

Closed
alvov-evo opened this issue Apr 26, 2024 · 4 comments · Fixed by #10494
Closed

Feature-Request: V8 support sub-Textures when creating BitmapFont objects #10482

alvov-evo opened this issue Apr 26, 2024 · 4 comments · Fixed by #10494
Assignees
Labels
🙏 Feature Request Community request for new features, APIs, packages.

Comments

@alvov-evo
Copy link
Contributor

Current Behavior

BitmapFont doesn't seem to use texture with defined frame but rather a source texture of that framed texture.

Expected Behavior

BitmapFont uses texture with defined frame.

Steps to Reproduce

Let there be multiple bitmap font textures combined into one sprite sheet file.

const sprite = new PIXI.Spritesheet(texture, data);
await sprite.parse();

const fontTexture = sprite.textures.font;

Create BitmapFont with a constructor as follows:

const font = new PIXI.BitmapFont({
    data: fontData,
    textures: [fontTexture],
});

Then create BitmapText using font family of this font:

    const bitmapFontText = new PIXI.BitmapText({
        text: 'some text,
        style: {
            fontFamily: 'Desyrel',
        },
    });

In that case BitmapFont doesn't seem to use fontTexture as source, but would rather use the whole sprite texture.

For instance, I've created a sprite sheet image with two Desyrel fonts: yellow on the left and green on the right.
Please check the playground: https://www.pixiplayground.com/#/edit/T5-gUiUddcNFhan8QaTPD
I pass the texture referring to the "green" texture to BitmapFont (so rendered text should be green), but it still seems to use the source sprite sheet texture (rendered text is yellow).
(Sorry for the somewhat messy playground example)

Environment

Possible Solution

No response

Additional Information

No response

@bigtimebuddy
Copy link
Member

Yeah, that's right, the fontTexture here assumes the fontData contains coordinates relative to the entire Texture's source. I would put this as a feature request since the behavior is currently undefined.

There seems to be a simple solution:

const charData = data.chars[key];
const textureSource = textures[charData.page].source;
const frameReal = new Rectangle(
charData.x,
charData.y,
charData.width,
charData.height,
);
const texture = new Texture({
source: textureSource,
frame: frameReal
});

We could simply offset Rectangle's x and y values by the Texture's frame. I think that would probably be enough!

@bigtimebuddy bigtimebuddy changed the title Bug: V8 BitmapFont doesn't respect texture with a set frame Feature-Request: V8 support sub-Textures when creating BitmapFont objects Apr 26, 2024
@bigtimebuddy bigtimebuddy added the 🙏 Feature Request Community request for new features, APIs, packages. label Apr 26, 2024
@alvov-evo
Copy link
Contributor Author

Thank you for the response!

I forgot to mention that the same case worked in version 7.x (7.3.2 at least), that's why I thought it's a regression.
Now that I know where to look at, I think it previously did a similar thing to what you've proposed:

const rect = new Rectangle(
x + (pageTextures[page].frame.x / res),
y + (pageTextures[page].frame.y / res),
width,
height
);

Any way, I can confirm this solution works for my case 🙇‍♂️

@bigtimebuddy
Copy link
Member

Nice. Would you mind making a PR for this change @alvov-evo?

@alvov-evo
Copy link
Contributor Author

@bigtimebuddy done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 Feature Request Community request for new features, APIs, packages.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants