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.

Displaying the Value's Stored in Variables anywhere on the screen?

I've asked this a few times but i'm still pretty confused about it and everyone keeps telling me to go look at HUD scripts. There are tons of HUD scripts out there that people have made that handles the displaying of hp, mp, gold, str, e.t.c, i know that, but most of them are intended for a specific purpose such as displaying a window with HP and MP for a battle engine.

What i've been looking for is a very simple script that allows you to display whatever values are stored inside a variable with just simple text and no borders, backgrounds or anything to go along with it anywhere onto the screen.

Example: You made your own custom shop, and when you talk to the shop keeper you display a picture you made with all the stuff you can buy and on the bottom right of the picture you left an empty area for where you are going to display the amount of gold you have using this variable display script i'm looking for.

The easiest way to put it is that i'm looking for a script where you can literally go into the event editor and put a call script command along the lines of
DrawText(140,480,$game_variables[1].to_s) where the parameters are (x coord, y coord, variable value you want displayed).

I hope that makes some kind of sense. Any kind of help is appreciated, and i'll definately make sure to credit anyone who can really help me out with this in my game.
 
Set the z value of the viewport....

    text_viewport = Viewport.new(0,0,640,480)
    text_viewport.z = 9000

And you need to make the size of the draw_text bigger than 12

    $scene.draw_text(320,240,12,12,"HP:")

by default, text is 22 pixels high.
 
Woot ty Brewmeister. I finally got it to display the words HP in the middle of my screen lol. I have two simple questions real quick

What is the syntax for displaying a variable? like #{$game_party.actors.size} would display the number of party members from the data base, what would i use for variables?

and also, is it easy to change the font and what not? like say if i want to use arial font, or times new roman, maybe bold or italicize it

Thanks again to the both of you. You guys are awesome, and i'll definately make sure to give you credit in my upcoming project.
 
How about bold and italicize? lol j/k :) Thank you for all your help Dargor and Brewmeister. I think i should be okay now. Now i understand why you are both staff here at rmxp.org. You are both awesome! Thanks again, and i won't forget to give either of you credit. Enjoy the rest of the day!
 
Dario, please don't email support requests to people. (Unless they ask you to.)
1) it's annoying
2) by taking the thread off-line, no one else benefits from the discussion.
Just add your question to the thread.

Dario Email":1ht7r37m said:
...could help me ... add some text manipulation to it such as the ability to change the color of the text, the size of the text, and the ability to make it bold.

Since @text_sprite is created when the map is initialized, it is always there. It's just empty until you put something in it.
So, at any time you can use the statements Dargor posted to change the Bold & Italic properties of the object.

Code:
@text_sprite.bitmap.font.size = 22

is the statement to change the size.

You can also change the color with:

Code:
clr = Color.new(255,255,255,255)
@text_sprite.bitmap.font.color = clr

where the values of Color.new are ( Red, Green, Blue, Alpha )

So, to make your "HP:" in extra large text, and italic, use:

Code:
@text_sprite.bitmap.font\
.italic = true
@text_sprite.bitmap.font.size\
 = 44
$scene.draw_text(280,210,120,60,"HP:")

The backslash (\) characters are only because the event script window is too small for the whole line.

You will also need to add the following line(4) to Dargor's code to be able to access the @text_sprite object from the event.

Code:
class Scene_Map
  alias dargor_req_draw_text_map_main main
  alias dargor_req_draw_text_map_update update
  attr_accessor :text_sprite
  def main
    text_viewport = Viewport.new(0,0,640,480)
    text_viewport.z = 9000
    @text_sprite = RPG::Sprite.new(text_viewport)
    @text_sprite.bitmap = Bitmap.new(640,480)
    dargor_req_draw_text_map_main
    @text_sprite.dispose
  end
  def update
    dargor_req_draw_text_map_update
    @text_sprite.update
  end
  def draw_text(x,y,width,height,text,align=0,clear_bitmap=true)
    @text_sprite.bitmap.clear if clear_bitmap
    @text_sprite.bitmap.draw_text(x,y,width,height,text,align)
  end
end

Be Well



Dargor, nice job cranking that out without RMXP to test. Perhaps you will soon share the rank of "Tool" with Seph & Trick :scruff:
 

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