Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

[Scripting]Centering drawTextEx

Status
Not open for further replies.

LTN Games

Master Mind
Resource Team
Xy$
0.01
Curious how one would go about centering drawTextEx according to the windows width? I mean I understand how to do it, but a bit stuck on getting it done correctly. So this is what I attempted...
Code:
  var tx = LTN.Param.windowWidth / 2 ;
Assuming this would center the X value of the text properly but then the issue occurs when the string is too long, making the string look like it starts in the middle and continues to the right, rather than getting an actual center alignment of the text. I know I can use drawText method which has a much better selection of options but then I loose the message codes that are available with drawTextEx. So my question is, how would I go about center aligning drawTextEx and if you can't is there a way to add the message codes to drawText ?

I know my first solution was to just do my code above but add in an offset option for users to adjust accordingly with the plugin command. Then I figured I would like to hear other peoples ideas on my issue first though lol. So lets hear it :D
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Go figure, I ended up finding how to get the strings width by using the Window Base method textWidth(string) then diving that by half, then in the X variable is the windoWidth /2 . This seems to perfectly align the text, where this originally centers the 0 position on the text to the center position of the window then I subtract half the text width so it's in the center of the text as well. Here is my code for others to learn from.

Code:
Window_Pop.prototype.drawCustomContents = function() {
  var popString   = WPOP._popString;
  var stringWidth = this.textWidth(popString) / 2;
  var tx = LTN.Param.windowWidth / 2 - stringWidth;
  this.drawTextEx(popString, tx, 0);
};
If I just waited a few minutes before posting for help I would have figured it out lol. We can still discuss other options if anyone wants to add to this topic. Anyways cheers :D
 

eivl

Local Hero
Xy$
0.00
Get width of screen
Get with of the drawn text box
Devide both in two to get the correct POS.

If you use drawText instead you can use center align.
Depends on what you need it for.
 
Status
Not open for further replies.
Top