A Look at Word-wrapping your Messages

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
In this article we will be looking at word-wrap and what an amazing feature it is. We will discuss word-wrap in RPG Maker and how it can be used, as well as some complications that arise because RPG Maker does not natively come with word-wrap.


What is Word Wrap?


Wikipedia has a pretty explanation on word wrap.


Word-wrap (and line-wrap) are features that determine when a line of text has reached the end of a line that they are displayed on and automatically starts a new line. The purpose of this is to avoid forcing the user to scroll horizontally to view the rest of the line (as in internet browsers), or to avoid having text cut off.


The difference between word-wrap and line-wrap is where the line break occurs. For line wrap, it will just print characters out, and once it hits the end of the line, it’ll print the next character on a new line. This may be undesirable because you might be in the middle of a word and now it doesn’t make sense. Some solutions to this include inserting a hyphen to indicate that the word continues on the next line. Sometimes it might even end up on a new page.


Word-wrap, on the other hand, will determine that it can’t print the whole word on the same line, and will start the word on the next line. This may be more desirable depending on whether you care whether words are broken apart or not.


Why It Matters


To appreciate these features, think about what happens when you don’t have them. For example, RPG Maker doesn’t have any word-wrap or line-wrap and so you end up with things like this:





Not very pretty. Or even correct: we’re missing two-and-a-half words, because the line was too long to fit on one line.


DIY


A solution? Manually insert line breaks!


RPG Maker attempts to help you by providing some visual guidelines. You can see that there are arrows in the show text message editor that indicate when the message will likely be cut off. The first arrow is used if you are showing a face graphic, while the second arrow is used if you don’t have a face graphic.


However, these guidelines assume a few things

  • You’re using the default font, and
  • You’re using the default window size, and
  • You’re using “plain text”
If you’re using larger or smaller fonts, those arrows aren’t very accurate (in fact it doesn’t seem very accurate for the default font either). If you want a larger or smaller window, those arrows won’t help either.
The more pressing issue is the assumption that you’re using “plain text”.


RPG Maker’s message window doesn’t just display text; it comes with a complete set of message codes that do a variety of things from controlling the speed of the text to showing the gold window to replacing certain codes with other values such as a specific actor’s name or a variable’s value.  These are called message codes, and it is a very large topic so I will not be covering that in detail here.


Basically, message codes that you write in the editor are not displayed the same way in game. Codes that control the message may or may not take up any space, while codes that convert codes into other text will likely take up more space. Of course, the editor doesn’t know this. I call them “Control Codes” and “Convert Codes”based on what their function is. You can see a list of default message codes when you hover your cursor over the text window:





Here’s an example of me following the guidelines and displaying a few variables using convert codes in my message:





While it looks fine in the editor, I can’t say the same about the results.


Read the rest at HimeWorks!
 
Last edited by a moderator:

Kaelan

Veteran
Veteran
Joined
May 14, 2012
Messages
797
Reaction score
537
First Language
Portuguese
Primarily Uses
RMMV
You may also want to mention the performance cost of real-time word wrapping. Regardless of how you implement it, you will have to at some point call text_size() multiple times, and it's not very fast.

The performance cost can be quite bad if you have a lot of text to display. The performance of the word-wrapping will decrease based on how much text is displayed at once. Something to keep in mind, especially if you're making a high resolution game, or have text-heavy features like character profile pages or bestiaries.

I've moved on to preprocessing the text in my game, word-wrapping everything except dialogue offline, then just reading the word-wrapped text from a file. Dialogue is the only text long enough to need line breaks but short enough to not have severe performance issues for me.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
You may also want to mention the performance cost of real-time word wrapping. Regardless of how you implement it, you will have to at some point call text_size() multiple times, and it's not very fast.


The performance cost can be quite bad if you have a lot of text to display. The performance of the word-wrapping will decrease based on how much text is displayed at once. Something to keep in mind, especially if you're making a high resolution game, or have text-heavy features like character profile pages or bestiaries.
I don't know what the performance cost is since I've never done any benchmarking.


Why would a large amount of text be a problem?


For example, if you have 10000 words, you probably can only show maybe 100 of them on the screen at once anyways. Unless drawing just 100 words is already going to require so much computation that it's going to be noticeably slow.


Pre-processing it would be preferred, if possible. If you have static text, you probably don't even need to use word-wrap.


However, with real-time data being supplied by message codes, that would be tricky.
 
Last edited by a moderator:

Kaelan

Veteran
Veteran
Joined
May 14, 2012
Messages
797
Reaction score
537
First Language
Portuguese
Primarily Uses
RMMV
I don't know what the performance cost is since I've never done any benchmarking.
You don't need to benchmark it, it's bad enough to visibly see the screen freezing and the mouse stuttering when text is being drawn

Why would a large amount of text be a problem?

For example, if you have 10000 words, you probably can only show maybe 100 of them on the screen at once anyways. Unless drawing just 100 words is already going to require so much computation that it's going to be noticeably slow.
Because any word wrapping algorithm is O(n) on number of words. And anything more than a paragraph or two is noticeably slow. I've had problems with this even back when my game was 640x480.



These description windows always took a second or two to pop-up because of the time word wrapping was taking.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I tried displaying 2000 words and it took almost a quarter of a second, which is pretty terrible.

Given that every time draw text is called, it needs to check the text size of a single character, that's easily several thousand calls right there.

For large pieces of text this would not be suitable, however if it's something like a show text message it shouldn't become too much of an issue.

Something else that I find strange is that it's constantly grabbing the text size of the same character over and over again rather than caching it somewhere and then pulling it.

Displaying the text "abcd abcd abcd ... " for 1000 "abcd's" required as much time as drawing 1000 random 4 letter combinations.

If the font doesn't change, you'd think it would be much faster to just cache the values and only do a full calculation if something changes.

I think Mithran has a font cache which might address this issue.

Though when I did something quick and simple like this

class Bitmap @@cache = {} alias :th_cached_text_size_text_size :text_size def text_size(str) @@cache[str] ||= th_cached_text_size_text_size(str) endendIt didn't make much of a difference, so there's probably something else..It doesn't help that the help docs says drawing text is time-consuming. Using Mithran's text cache sort of helps.

Given these results, I'd only use word-wrap for small amounts of text.
 
Last edited by a moderator:

TMS

Guy with Mask
Veteran
Joined
Apr 17, 2012
Messages
310
Reaction score
59
First Language
English
Primarily Uses
N/A
I'll have to look into this. I started a topic about the lack of word wrap and people treated me like I was some kind of idiot for missing it.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,061
Members
137,575
Latest member
akekaphol101
Top