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

feat: Added ability to render spritesheet-based fonts #1634

Merged
merged 30 commits into from
Jun 3, 2022

Conversation

st-pasha
Copy link
Contributor

@st-pasha st-pasha commented May 17, 2022

Description

This PR adds [SpriteFontRenderer], which is a new implementation of [TextRenderer], allowing to render text based on fonts embedded into a spritesheet.

See the T-Rex game example, where the score is now rendered based on a spritesheet font.

(Also added highscore tracking for the TRex game).

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples.

Breaking Change

  • [-] Yes, this is a breaking change.
  • No, this is not a breaking change.

Related Issues

Closes #1621

Copy link
Member

@erickzanardo erickzanardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! I have one suggestion though.

TextPaint is an immutable class IIRC, and for consistency I think we should that on this renderer too, so instead of a addGlyph method, we could have a new attribute on the constructor to receive the metadata of mapped glyphs. Other than that, this looks great!

wdyt?

packages/flame/lib/src/text/sprite_font_renderer.dart Outdated Show resolved Hide resolved
Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, glad to see that the T-Rex game is already getting improvements too!
I agree with Erick's suggestions too.

@st-pasha
Copy link
Contributor Author

TextPaint is an immutable class IIRC, and for consistency I think we should that on this renderer too, so instead of a addGlyph method, we could have a new attribute on the constructor to receive the metadata of mapped glyphs. Other than that, this looks great!

wdyt?

We could make something like SpriteFontBuilder which would have the addGlyph() method, and then .build() will return an instance of SpriteFontRenderer (which would not be constructible directly).

Need to keep an eye on future ability of create new SpriteFontRenderers out of an existing SpriteFontRenderer. For example, create a different-sized variant of the same font.

@erickzanardo
Copy link
Member

Need to keep an eye on future ability of create new SpriteFontRenderers out of an existing SpriteFontRenderer. For example, create a different-sized variant of the same font.

I don't think that making this immutable would disallow that, we can take TextStyle from flutter itself as an example, where it provides a copyWith method, that same approach would work great on this too IMO

Copy link
Member

@erickzanardo erickzanardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, can't wait to use this.

@erickzanardo erickzanardo merged commit 3f28789 into flame-engine:main Jun 3, 2022
@st-pasha st-pasha deleted the ps/sprite-font-renderer branch June 3, 2022 19:38
st-pasha added a commit to st-pasha/flame that referenced this pull request Jun 3, 2022
)

This PR adds [SpriteFontRenderer], which is a new implementation of [TextRenderer], allowing to render text based on fonts embedded into a spritesheet.

See the T-Rex game example, where the score is now rendered based on a spritesheet font.

(Also added highscore tracking for the TRex game).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for sprite-based text rendering
4 participants