Joined
Jun 27, 2021
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMMZ
I have been working on a plugin for making message windows fit to the size of messages, and I noticed something quite odd. In some cases, the message would be cut off where in others it would fit just fine. I assumed at first this to be an error with my own code, but was surprised when disabling all plugins and even resetting to the default font did not prevent the text placement from deviating.

After some testing, it seemed to me that when text in message windows is shown instantly, it has the proper spacing. But when you allow the game to draw it one character at a time, it seems to stretch out. I've cropped a couple of samples to show the difference here. I didn't notice anyone else mentioning this bug, so I figured I probably should bring it up. And again, this happens with NO plugins enabled and the default font on. If there's anything else I might have overlooked to have this be a problem on my end, do let me know.
 

Attachments

  • sample.PNG
    sample.PNG
    109 KB · Views: 23

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,743
Reaction score
2,095
First Language
EN
Primarily Uses
RMMZ
I tried this event in a new project and saw no difference in line length:

◆Text:None, Nature(4), Window, Bottom : :Hello this is some text and this is more text. : :\>Hello this is some text and this is more text. ◆Text:None, Nature(4), Window, Bottom : :Hello this is some text and this is more text. ◆Text:None, Nature(4), Window, Bottom : :\>Hello this is some text and this is more text.
Can you share the steps necessary to create the issue you're seeing in a new project?
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
43,325
Reaction score
15,154
First Language
English
Primarily Uses
RMMV
I am also not able to reproduce the issue, but in my case, I didn't use escape codes - I simply let the message play character by character in the first instance, but in the second I clicked to make it skip to the end.

Sometimes people think plugins are not active, but they actually are. Can you try in a brand new project without ANY plugins added/activated, and see if you can make it happen? Can you show a picture of the event so we can see the command, and explain what you're doing to make it show instantly vs character-at-a-time, as @caethyril assumed you meant one thing and I assumed you meant something else (and we might both be wrong)?
 
Joined
Jun 27, 2021
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMMZ
Yeah, actually trying it in a new project I can't seem to get it to happen anymore. I was testing it in my main one with like, all the plugins disabled, but there's a real possibility that I overlooked something there. I'd done some fiddling with the font settings and I THOUGHT I'd gotten them all back to default but I think the error was probably on my end. Must admit, there was a little bit of frustration at not being able to figure out why the message windows I'd slaved away on for weeks were bugging out on me, I think I didn't do due diligence in testing.

Funny thing is I actually managed to fix it for my project. Going back through the old versions of the source code:

Bitmap.prototype.measureTextWidth = function(text) { const context = this.context; context.save(); context.font = this._makeFontNameText(); const width = context.measureText(text).width; context.restore(); return Math.ceil(width); };

Changing return Math.ceil(width) back to just return width caused the problem to stop occurring for me.

Figured I'd share as much in case anyone else runs into a similar problem. But, yeah, this is not a bug in MZ, it's a bug in me.
 

Archeia

Level 99 Demi-fiend
Staff member
Developer
Joined
Mar 1, 2012
Messages
15,463
Reaction score
15,911
First Language
Filipino
Primarily Uses
RMMZ
Reopened this just in case and for me to refer back later.
This is the bug in action. It is easier to replicate it with a wider font:
1631611136118.png

The bug is related to Text Flushing. Somewhere around here:
Code:
Window_Message.prototype.updateMessage = function() {
    const textState = this._textState;
    if (textState) {
        while (!this.isEndOfText(textState)) {
            if (this.needsNewPage(textState)) {
                this.newPage(textState);
            }
            this.updateShowFast();
            this.processCharacter(textState);
            if (this.shouldBreakHere(textState)) {
                break;
            }
        }
        this.flushTextState(textState);
        if (this.isEndOfText(textState) && !this.isWaiting()) {
            this.onEndOfText();
        }
        return true;
    } else {
        return false;
    }
};

Solution should be simple as to rewrite flushing or the flush aspect so that it checks the textState index. Then continues to draw from that point onwards in a single frame. I'll see if I can do an independent fix.

Here is a sample project that will 100% replicate it.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,743
Reaction score
2,095
First Language
EN
Primarily Uses
RMMZ
I did a quick test and removing the rounding on Bitmap#measureTextWidth (rmmz_core) seems to make all lines the same length:
JavaScript:
/*:
 * @target MZ
 * @plugindesc quick fix for text flushing bug?
 */

// Override! Do not round up the return value.
Bitmap.prototype.measureTextWidth = function(text) {
    const context = this.context;
    context.save();
    context.font = this._makeFontNameText();
    const width = context.measureText(text).width;
    context.restore();
    return width;   // <- removed Math.ceil
};
As I understand it, though, rendering at fractional coordinates can cause aliasing/blurriness. I don't know if it'd be better to flush each character separately with integer coordinates instead?
 

Archeia

Level 99 Demi-fiend
Staff member
Developer
Joined
Mar 1, 2012
Messages
15,463
Reaction score
15,911
First Language
Filipino
Primarily Uses
RMMZ
I did a quick test and removing the rounding on Bitmap#measureTextWidth (rmmz_core) seems to make all lines the same length:
JavaScript:
/*:[/INDENT][/INDENT]
[INDENT][INDENT]* @target MZ[/INDENT][/INDENT]
[INDENT][INDENT]* @plugindesc quick fix for text flushing bug?[/INDENT][/INDENT]
[INDENT][INDENT]*/[/INDENT][/INDENT]
[INDENT][INDENT][/INDENT][/INDENT]
[INDENT][INDENT]// Override! Do not round up the return value.[/INDENT][/INDENT]
[INDENT][INDENT]Bitmap.prototype.measureTextWidth = function(text) {[/INDENT][/INDENT]
[INDENT][INDENT]    const context = this.context;[/INDENT][/INDENT]
[INDENT][INDENT]    context.save();[/INDENT][/INDENT]
[INDENT][INDENT]    context.font = this._makeFontNameText();[/INDENT][/INDENT]
[INDENT][INDENT]    const width = context.measureText(text).width;[/INDENT][/INDENT]
[INDENT][INDENT]    context.restore();[/INDENT][/INDENT]
[INDENT][INDENT]    return width;   // <- removed Math.ceil[/INDENT][/INDENT]
[INDENT][INDENT]};
As I understand it, though, rendering at fractional coordinates can cause aliasing/blurriness. I don't know if it'd be better to flush each character separately with integer coordinates instead?

Yeah if we do it this way, it will cause "Text and actor faces extremely blurry sometimes due to non-integer coordinates" bug to reappear. Maybe let's try this instead:

Code:
Bitmap.prototype.measureTextWidth = function(text) {
    const context = this.context;
    context.save();
    context.font = this._makeFontNameText();
    const width = context.measureText(text).width;
    context.restore();
    return this._window_message ? width : Math.ceil(width);
};

Window_Message.prototype.textWidth = function(text) {
    this.contents._window_message = true;
    return this.contents.measureTextWidth(text);
};
 
Last edited:

Latest Threads

Latest Profile Posts

I couldn't help myself, so I edited the tiles a bit and made a birdhouse :LZSsmile: I hope I will finish the town today!Screenshot 2021-09-17 134349.png
How do I find the threads I have watched? It's been so long I've forgotten :kaoswt:
So far, this is how the wall tileset its looking in-editor. :kaoswt2:
1631863283853.png
Still thinking on details to add.
Added a plugin to RMMV Plugin Releases with all relevant info but it looks like the topic wasn't approved for whatever reason. Cool.
Working in the IT industry:
- "How long does it take?".
- "It takes 1 month".
- "What if we add more people to the project?".
- "It would take 2 months".

Forum statistics

Threads
115,130
Messages
1,087,463
Members
149,637
Latest member
3hunnaz
Top