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.

Adding text

Anonymous

Guest

You're going to want to make a new window class for that. Something like this:

Code:
class Window_Location < Window_Base
  def initialize
    super(0, 0, 240, 60)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.z = 9999
    refresh
  end
  
  def refresh
    self.contents.clear
    
    text = $game_map.name
    cx = contents.text_size(text).width
    self.contents.font.color = shadow_color
    self.contents.draw_text(1, 5, 120, 32, text, 2)
    
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 4, 120, 32, text, 2)
  end

  def update
    super
    refresh
  end
end

Then make a new window of that type:

Code:
location_window = Window_Location.new
 

Anonymous

Guest

You can put it anywhere, but I recommend putting it in its own file. You make a new window class like this:

Code:
class My_Window < Window_Base
end

That gives you a new window class, My_Window. Then you'd want to add the data to initialize it, like so:

Code:
class My_Window < Window_Base
  def initialize
    super(50,100,520,192)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
end

That tells the interpreter that whenever you create a new object of the class My_Window (by calling My_Window.new), you need to call the initialize method in the super class, which is Window_Base. That will create a window of the size and in the position you wanted. Then it creates a new bitmap to be the actual drawing pane of the window.

Next, add text.


Code:
class My_Window < Window_Base
  def initialize
    super(50,100,520,192)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end

  def refresh
    self.contents.clear
    text = 'my text'
    self.contents.draw_text(0, 0, 250, 32, text)
  end 
end

We added the method refresh, which draws "my text" on the window, and then called that method from the initialize method, so that the window starts with that text on it.
 

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