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.

Drawing made variables.

khmp

Sponsor

I believe it would be:
'self.contents.draw_text(self.contents.text_size($game_variables[n].to_s), $game_variables[n].to_s)'

'n' is the index of which variable you want to draw.

If you want to specify the coordinates of where you want the variable to be drawn.

'self.contents.draw_text(x,y,width,height, $game_variables[n].to_s)'

Good luck! :thumb:

Quick Example:
Code:
class HUD_Window < Window_Base
  def initialize
    # Call the parent's initialize.
    super(0, 0, 100, 100)
    # Create a surface so we can draw on it.
    self.contents = Bitmap.new(width - 32, height - 32)
    # Specify a text color.
    self.contents.font.color = text_color(0)
    # Initialize our first game variable so it isn't nil when drawn.
    $game_variables[0] = 25
    # This will draw the number 25 at the upper left of the window.
    self.contents.draw_text(self.contents.text_size($game_variables[0].to_s), 
                    $game_variables[0].to_s)
  end
  
  def dispose
    self.contents.dispose
    super
  end
end
 
This should make a little window showing the variable's value.
Code:
class Window_Hud < Window_Base  

  ID = 10

  def initialize
    super(0, 0, 160, 64)
    self.contents = Bitmap.new(128, 32)
    refresh
  end
  def refresh
    @value = $game_variables[ID]
    contents.clear
    contents.draw_text(0, 0, 128, 32, @value.to_s)
  end
  def update
    refresh if @value != $game_variables[ID]
  end
end

class Scene_Map
  alias main1 main
  alias update1 update
  def main
    @hud = Window_Hud.new
    main1
    @hud.dispose
  end
  def update
    @hud.dispose
    update1
  end
end
 

khmp

Sponsor

My apology badmonur. In order for the window/hud to appear it must first be created in the scene you want it to show. But as Slipknot also coded the window should be disposed of as well.
 

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