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.

Why i cant put Text in this window....

xppxdd

Member

here is my code(not really main, im editing*)



Code:
#Script: Hud - Hp / Mp / EXP Bar

#Made By: Dark Tornado

#edit by Ariel_tete94

#Ver: 1.2

#Date: 20/12/09

 

class Sprite_Hud

  def initialize

    draw_hud

  end

  def draw_hud

    @hp_bar = Sprite.new

    @bg_hp_bar = Sprite.new

    @mp_bar = Sprite.new

    @bg_mp_bar = Sprite.new

    @exp_bar = Sprite.new

    @bg_exp_bar = Sprite.new

    

    @background = Sprite.new

    @background.bitmap = RPG::Cache.hud("main_bg_hud.png") 

    @background.z = 98

    @background.tone.gray = 255

 

    @bg_hp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png") 

    @bg_hp_bar.z = 99

    @bg_hp_bar.x = 137

    @bg_hp_bar.y = 50

    @bg_hp_bar.tone = Tone.new(-85,-85,-85,100)

 

    @hp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png")

    @width = @hp_bar.bitmap.width

    @hp_bar.x = @bg_hp_bar.x

    @hp_bar.y = @bg_hp_bar.y

    @hp_bar.z = 100

    

    @bg_mp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png",225) 

    @bg_mp_bar.z = 99

    @bg_mp_bar.x = 137

    @bg_mp_bar.y = 70

    @bg_mp_bar.tone = Tone.new(-85,-85,-85,100)

    

    @mp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png",225) 

    @mp_bar.z = 100

    @mp_bar.x = 137

    @mp_bar.y = 70  

    

    

    @bg_exp_bar.bitmap = RPG::Cache.hud("main_exp_hud.png") 

    @bg_exp_bar.z = 99

    @bg_exp_bar.x = 2

    @bg_exp_bar.y = 62

    @bg_exp_bar.tone = Tone.new(-85,-85,-85,100)

 

    @exp_bar.bitmap = RPG::Cache.hud("main_exp_hud.png")

    @width = @exp_bar.bitmap.width

    @exp_bar.x = @bg_exp_bar.x

    @exp_bar.y = @bg_exp_bar.y

    @exp_bar.z = 100

    

 

  end

  def update

    draw_hud if (@hp_bar == nil or @hp_bar.disposed?)

    @xscale = ($game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp.to_f * @width.to_f).to_f

    @hp_bar.src_rect.width = @xscale

    @xscale2 = ($game_party.actors[0].sp.to_f / $game_party.actors[0].maxsp.to_f * @width.to_f).to_f

    @mp_bar.src_rect.width = @xscale2

    @xscale2 = ($game_party.actors[0].exp_s.to_f / $game_party.actors[0].next_exp_s.to_f * @width.to_f).to_f

    @exp_bar.src_rect.width = @xscale2

  end

  def dispose

    @hp_bar.dispose

    @bg_hp_bar.dispose

    @mp_bar.dispose

    @bg_mp_bar.dispose

    @background.dispose

        @exp_bar.dispose

    @bg_exp_bar.dispose

    @hp_bar = nil

    @bg_hp_bar = nil

        @exp_bar = nil

    @bg_exp_bar = nil

    @mp_bar = nil

    @bg_mp_bar = nil

    @background = nil

  end

end

 

 

class Spriteset_Map

  alias initialize_hud initialize

  alias update_hud update

  alias dispose_hud dispose

  def initialize

    @hud = Sprite_Hud.new

    initialize_hud

  end

  def update

    update_hud

    @hud.update

  end

  def dispose

    dispose_hud

    @hud.dispose

  end

end

module RPG

  module Cache

    def self.hud(filename, hue = 0)

      self.load_bitmap("Graphics/Huds/", filename, hue)

    end

  end

end

  

    

 

 



i chenge some sprite and made a EXP bar.
i have two questions:
1. how i make a text in this class/window IDK...(next to the EXP bar (screenshot down)
2. how i make a % label with the % of the player EXP? (like in most of the GAME)

asasasr.png

http://img300.imageshack.us/i/asasasr.png/
 
This is an odd script. We all have our way to do things but this one is weirdly done...

Anyway, about your first question:

All you need to draw text is a bitmap. In the case of this script, you can use a sprite (that contains a bitmap) to draw it.

Try using this:
@exp_bar.bitmap.draw_text(x,y,width,height,text)

Place it below "@exp_bar = Sprite.new and simply change the 5 parameters to fit your needs.


Now, about your second question:

This time it's a bit trickier.
We will need a couple of variables and a simple formula, then we will draw the result on screen like we did above.

First step, we need to find the difference between the current level's required EXP and next level's EXP. I recommend making doing all this stuff in a new method in the Game_Actor class.

This method should look like that:
[ruby] 
def total_exp_to_next_level
  # we calculate the difference
  result = @exp_list[@level + 1] - @exp_list[@level]
  # we return the result
  return result
end
 
[/ruby]

Second step, we need to calculate the percentage. Let's create another method.
[ruby] 
def required_exp_percent
  # we calculate the difference between the current exp and the exp required for the current level
  now_exp = @exp - @exp_list[@level]
  # we convert the value of now exp into percent based on the exp given by our previous method
  result = (now_exp * 100) / total_exp_to_next_level
  # we return the result
  return result
end
 
[/ruby]

Final step! Do as we did above to draw text on screen, but this time, the "text" parameter will be different. Instead of a string, use the following line of code:
$game_party.actors[0].required_exp_percent.to_s

It now should look like this:
@exp_bar.bitmap.draw_text(x,y,width,height,$game_party.actors[0].required_exp_percent.to_s + "%")

I think that's it. I haven't test it because I'm at work.
Let me know if I missed something, if there's an error somewhere, if i went way too technical on some things, or anything else.

Hope it helps!
-Dargor
 

xppxdd

Member

IDK why it make a duble post again!
its heppend all the time!!!!

working but its like, chenge the label but with "0"behind...
like he didnt chenge the 0 from the start and he just make anather label..
where to put the text look if i put right. (i put the Game_Actor)

Code:
#Script: Hud - Hp / Mp / EXP Bar Also Name / Level / Class Labels

#Base on Dark Tornado Script.

#edit by Ariel_tete94

#Ver: 1.6

#Date: 20/12/09

 

class Sprite_Hud

  def initialize

    draw_hud

  end

  def draw_hud

    @hp_bar = Sprite.new

    @bg_hp_bar = Sprite.new

    @mp_bar = Sprite.new

    @bg_mp_bar = Sprite.new

    @exp_bar = Sprite.new

    @bg_exp_bar = Sprite.new

    @sprite = Sprite.new

    @actor = $game_party.actors[0]

    @explabel = @actor.exp / @actor.next_exp_s.to_i * 100

    

    

 

 

     

         #TEXT

      

      @sprite.bitmap = RPG::Cache.hud("main_bg_hud.png")

    @sprite.bitmap.font.size = 25

      @sprite.bitmap.draw_text(40, -16, 100, 100, @actor.level.to_s, 1)

    @sprite.bitmap.font.size = 16

      @sprite.bitmap.draw_text(35, 5, 100, 100, @actor.name.to_s, 1)

      @sprite.bitmap.draw_text(37, 25, 100, 100, @actor.class_name.to_s, 1)

      @sprite.bitmap.draw_text(123,35,100,100,$game_party.actors[0].required_exp_percent.to_s + "%")

    

      #END

     

    @background = Sprite.new

    @background.bitmap = RPG::Cache.hud("main_bg_hud.png") 

    @background.z = 98

    @background.tone.gray = 255

 

    @bg_hp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png") 

    @bg_hp_bar.z = 99

    @bg_hp_bar.x = 137

    @bg_hp_bar.y = 52

    @bg_hp_bar.tone = Tone.new(-85,-85,-85,100)

 

    @hp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png")

    @width = @hp_bar.bitmap.width

    @hp_bar.x = @bg_hp_bar.x

    @hp_bar.y = @bg_hp_bar.y

    @hp_bar.z = 100

    

    @bg_mp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png",225) 

    @bg_mp_bar.z = 99

    @bg_mp_bar.x = 137

    @bg_mp_bar.y = 74

    @bg_mp_bar.tone = Tone.new(-85,-85,-85,100)

    

    @mp_bar.bitmap = RPG::Cache.hud("main_hp_hud.png",225) 

    @mp_bar.z = 100

    @mp_bar.x = 137

    @mp_bar.y = 74

    

    

    @bg_exp_bar.bitmap = RPG::Cache.hud("main_exp_hud.png") 

    @bg_exp_bar.z = 99

    @bg_exp_bar.x = 2

    @bg_exp_bar.y = 59

    @bg_exp_bar.tone = Tone.new(-85,-85,-85,150)

 

    @exp_bar.bitmap = RPG::Cache.hud("main_exp_hud.png")

    @width = @exp_bar.bitmap.width

    @exp_bar.x = @bg_exp_bar.x

    @exp_bar.y = @bg_exp_bar.y

    @exp_bar.z = 100

 

 

  end

  def update

    draw_hud if (@hp_bar == nil or @hp_bar.disposed?)

    @xscale = ($game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp.to_f * @width.to_f).to_f

    @hp_bar.src_rect.width = @xscale

    @xscale2 = ($game_party.actors[0].sp.to_f / $game_party.actors[0].maxsp.to_f * @width.to_f).to_f

    @mp_bar.src_rect.width = @xscale2

    @xscale2 = ($game_party.actors[0].exp_s.to_f / $game_party.actors[0].next_exp_s.to_f * @width.to_f).to_f

    @exp_bar.src_rect.width = @xscale2

 

 

    

  end

  def dispose

    @hp_bar.dispose

    @bg_hp_bar.dispose

    @mp_bar.dispose

    @bg_mp_bar.dispose

    @background.dispose

        @exp_bar.dispose

    @bg_exp_bar.dispose

    @hp_bar = nil

    @bg_hp_bar = nil

        @exp_bar = nil

    @bg_exp_bar = nil

    @mp_bar = nil

    @bg_mp_bar = nil

    @background = nil

  

  end

end

 

 

class Spriteset_Map

  alias initialize_hud initialize

  alias update_hud update

  alias dispose_hud dispose

  def initialize

    @hud = Sprite_Hud.new

    initialize_hud

  end

  def update

    update_hud

    @hud.update

  end

  def dispose

    dispose_hud

    @hud.dispose

  end

end

module RPG

  module Cache

    def self.hud(filename, hue = 0)

      self.load_bitmap("Graphics/Huds/", filename, hue)

    end

  end

end

in line 34
 

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