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?
How do I align text to the center of a text box?
RPG Maker MV SupportThe Window_Base.drawText() method has a parameter for alignment which will take "center".
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.
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.
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.
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.
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.
Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-align-text-to-the-center-of-a-text-box.95750/