How do I align text to the center of a text box?

jaret742

Villager
Member
Joined
Jun 25, 2016
Messages
16
Reaction score
2
First Language
English
Primarily Uses
RPG Maker MV does not have a center-align function, and neither does Yanfly's Message Core plugin. Is there another plugin that I can use, or do I need to center the text by dividing the screen width by 2?
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,704
Reaction score
2,208
First Language
English
Primarily Uses
RMMV
The Window_Base.drawText() method has a parameter for alignment which will take "center".
 

jaret742

Villager
Member
Joined
Jun 25, 2016
Messages
16
Reaction score
2
First Language
English
Primarily Uses
upload_2018-5-26_14-58-40.png
I found the code, but where do I put "center"? I tried replacing "left" on line 265 with it, but when I opened my game, the text was still on the left side.
 

djDarkX

Retro & Remastered Music Guru
Veteran
Joined
Jan 17, 2013
Messages
2,700
Reaction score
1,901
First Language
Music
Primarily Uses
RMMV
Because of the way MV draws message boxes, centering text is not a thing. Believe me, a few of us have asked for something like this since MV came out and nothing ever came of it. If you're trying to get the same functionality that you could get in previous Makers, it's not gonna happen without a major rework of how the text is drawn. There are other options, but they are "workarounds" or other ways of doing it without the proper effect you're looking for.
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,704
Reaction score
2,208
First Language
English
Primarily Uses
RMMV
Edit: Disregard what I said. I thought this was in the JavaScript section and was asking about drawing text to a window. I haven't looked into how message boxes are created yet but if no one has made a plugin for this by now, it's a good bet that it's not feasible. Sorry about the confusion.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
Like @djDarkX says, it's a little tricky for the message window because by default it draws each character in turn, so the align parameter of drawText will only centre each character in its own little box. Yanfly's Message Core adds a wordwrap feature that checks word by word for the width to exceed the remaining space and if so moves to the next line, but that's not quite enough to help here.

To centre each line I think you'd need to calculate the textWidth of the whole line first. Then you can determine the necessary offset (i.e. x position for first character of that line) and draw the text as usual. It would involve several overrides, but I'm surprised it's not been done yet. Maybe I'm missing something.
 

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,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top