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.

[XP] How to center the text in my location script?

Hello,

Well, like the title says: how to center the text in my location script?

Code:
#==============================================================================
# ** Window_Location
#------------------------------------------------------------------------------
#  This window displays your current loacation
#==============================================================================

class Window_Location < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 230, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    $data_map_infos = load_data("Data/MapInfos.rxdata")
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.size = 18
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 120, 32, $data_map_infos[$game_map.map_id].name)
  end
end

Thanks in advance,
Budsie
 
Doesn't work. Already tried that.
What does work is this:
Code:
self.contents.draw_text(0, 0, 200, 32, $data_map_infos[$game_map.map_id].name,1)
But my location window's width is 230 and the text width is 200. Kinda weird or not?
 
The answer is here :
Code:
self.contents = Bitmap.new(width - 32, height - 32)

You draw the text on the bitmap and not on the window ^^
So the 'perfect' center is 230-32, so 198 !
Code:
self.contents.draw_text(0, 0, 198, 32, $data_map_infos[$game_map.map_id].name,1)

So it's not weird ^^
The last number is 0 (or nothing) to left justify, 1 to center and 2 to right justify.
 

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