Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[RESOLVED] Changing Font Size, Color

I'm curious about how to change the font size and color in the message window at any given time. In searching through some older threads, I found this bit of code:

Code:
def message_font=(font)
    return if font.nil? || !font.is_a?(String)
    @message_window.contents.font.name = font
  end

This works perfectly for adjusting the font itself whenever, and I tried similar code to adjust the size (@message_window.contents.font.size = size, in a separate section called message_size), but it didn't work. The font size remained the same.

What did I do wrong?
 

e

Sponsor

Could you post the code you used to change the font size?

Taken from the help file:

size
The font size. The default is 22 points.

Theoretically, setting "font.size=something" would change the font's size to "something", provided "something" is an integer (meaning rounded number: 33, 10, 44, etc.)

However, if you change the font name tom something else, I assume it would revert back to its original size, the Font.default_size class property.

If you want the font to always be the same size, regardless of its name, try doing:

Code:
Font.default_size=99

Where 99 is your font size. Else, like I said, "@message_window.contents.font.size = size" would set it to whatever value "size" holds, but keep in mind it would do so ONLY for that particular instance of the class (the @message_window object). In other words, it would work only for that window, not the others.
 
The code I have to change the font size is:

Code:
def message_size=(font)
    return if font.nil? || !font.is_a?(String)
    @message_window.contents.font.size = size
  end

Edit: Just tried a small change, switched it to

Code:
  def message_size=(size)
    return if size.nil? || !size.is_a?(String)
    @message_window.contents.font.size = size
  end

and still got nothing to change.

But when I call it using a script, with say

Code:
$scene.message_size = 36

it doesn't work, the font remains the same size. I'm also curious on how to change font color in a  similar method, changing it for each window. Using that calling method works fine for changing font size, though.

Code:
$scene.message_font = 'Comic Sans MS'

does indeed change the font to Comic Sans MS for a single window.

What I'm going for is for each character to have their own font, size and color when they speak.
 

khmp

Sponsor

Haha I made that for someone although I can't recall who.

The problem with the changing the size is this check:
Code:
return if size.nil? || !size.is_a?(String)

Size isn't a string in this case the check would be for integer.
Code:
return if size.nil? || !size.is_a?(Integer)

Color would travel the same path.
Code:
  def message_color=(color)
    return if color.nil? || !color.is_a?(Color)
    @message_window.contents.font.color = color
  end

A color is four separate components Red, Green, Blue, Alpha each range 0-255. And if you want full opacity on the font you can omit the fourth parameter in the color's creation.
Code:
$scene.message_color = Color.new(255,0,0) # Red at full opacity.

This code was created for a state machine change per window. To change the font and other properties within the window per character stuff you will need to turn to an AMS. Like ccoa's UMS, dubleax AMS or slipknots AMS.

Good luck with it Fernin320! :thumb:
 
Thanks much, khmp! Size and color are both working now.  :smile:
Now, one last question... how would I go about setting up italics and bold font? Same case as above, I have one character who always speaks in italics, one character who always speaks in italics and bold, so affecting a single message window would be best. I don't much care about affecting a single word.
 

khmp

Sponsor

Both italic and bold are booleans(true/false), so the check would become something like this:
Code:
  def message_bold=(bold)
    return if bold.nil? || (!bold.is_a?(TrueClass) && !bold.is_a?(FalseClass))
    @message_window.contents.font.bold = bold
  end

  def message_italic=(italic)
    return if italic.nil? || (!italic.is_a?(TrueClass) && !italic.is_a?(FalseClass))
    @message_window.contents.font.italic = italic
  end

Good luck with it Fernin320! :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top