The Colon Case - Wrapping Text in SFML

Published April 30, 2021
Advertisement

In my previous post, I presented a simple FontFamily class. This was just the first step in being able to render large blocks of text for my upcoming detective game, The Colon Case.

When SFML renders text on the screen, it will only wrap that text to a new line if the string actually contains newline characters. I wanted to be able to define a position and maximum width per line, and have the text wrap naturally. I want this to be done dynamically, as I plan to have a menu option available for font size.

In my SFML utilities Git repository, I'm working on a new feature to handle this. So far, it handles horizontal alignment (left, center, and right justification). I'm working on vertical alignment and rotation as well, just for the sake of completion. Below is a screenshot from a simple example program making use of the feature.

One small issue I came across involved rounding issues when dealing with floating point values. When SFML renders text at a fractional pixel position, it can sometimes have a blurry appearance. It almost always looks best to render text at integer co-ordinates, without any scaling or fractional spacing. So I included a rounding correction flag that can be toggled, based on particular needs.

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement
Advertisement