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.

Picture with text boxes

OS

Sponsor

Hello, again. I normally don't do graphic based scripts, but my boss wants me to display an image and show dynamic text in 4 boxes.

All I need to know is how to manipulate a file I load with RPG::Cache.picture("HUD") so that it sits in the bottom left corner, and how to show text in the text fields placed on the image. I think I have to create a bitmap for each text box, but I'm not sure. Thanks for any help. Peace!
 
Well, a simple sprite to make that can be like this :)
Code:
class Sprite_HUD < Sprite

  def initialize
   super()
   self.bitmap = RPG::Cache.picture('HUD')
   self.x = 8
   self.y = 472 - self.bitmap.height
   @text = Sprite.new
   self.x = @text.x = 8
   self.y = @text.y = 472 - self.bitmap.height
   @text.bitmap = Bitmap.new(bitmap.width, bitmap.height)
   # Draws text...
   @text.bitmap.draw_text(0, 0, bitmap.width, 32, 'Some text')
   @text.bitmap.draw_text(8, 32, bitmap.width - 8, 32, 'more text')
  end
end
 

OS

Sponsor

Oh, thanks. I haven't used the Sprite class for anything in such a long time that I forgot about it :p

Thanks for the help, Slipknot! I'll check this right away.

EDIT: Alright, the image shows now, but the text is white. I tried changing it with @text.bitmap.font.color = Color.new(255,255,255,0), but it (and every other color I tried) made the text invisible. Also, I'm having trouble getting the text to update. This is for a clock, so the text is supposed to update at various points. One text is supposed to change every frame/second, while the other boxes are supposed to update when their update methods are called. But it isn't working. Any help is always appreciated. Peace!

EDIT2: Nevermind. I didn't realize that the Alpha Channel at 0 would do that. I fixed it. But I still need help with the update methods.

EDIT3: Fixed the Update problem. Now I am having an other problem:

I am using a case method to determine which picture should be loaded. For some reason, when the code hits 'when 1', the picture isn't loaded, and every time it starts from 1 again, none of the pictures will load when they are supposed to. Peace!
 

OS

Sponsor

Sorry. This Sprite is updated every in game hour (speed test was about every twelve seconds)

Code:
lass Sprite_Wheel < Sprite
  def initialize
   super()
   self.bitmap = RPG::Cache.picture("Wheel2")
   self.x = 160
   self.y = 460 - self.bitmap.height
   refresh
 end
 
 def refresh
   self.bitmap.clear
   @hour = $game_time.hour?(24)
   case @hour
   when 1
     self.bitmap = RPG::Cache.picture("Wheel1")
   when 2
     self.bitmap = RPG::Cache.picture("Wheel2")
   when 3
     self.bitmap = RPG::Cache.picture("Wheel3")
   when 4
     self.bitmap = RPG::Cache.picture("Wheel4")
   when 5
     self.bitmap = RPG::Cache.picture("Wheel5")
   when 6
     self.bitmap = RPG::Cache.picture("Wheel6")
   when 7
     self.bitmap = RPG::Cache.picture("Wheel7")
   when 8
     self.bitmap = RPG::Cache.picture("Wheel8")
   when 9
     self.bitmap = RPG::Cache.picture("Wheel9")
   when 10
     self.bitmap = RPG::Cache.picture("Wheel10")
   when 11
     self.bitmap = RPG::Cache.picture("Wheel11")
   when 12
     self.bitmap = RPG::Cache.picture("Wheel12")
   when 13
     self.bitmap = RPG::Cache.picture("Wheel1")
   when 14
     self.bitmap = RPG::Cache.picture("Wheel2")
   when 15
     self.bitmap = RPG::Cache.picture("Wheel3")
   when 16
     self.bitmap = RPG::Cache.picture("Wheel4")
   when 17
     self.bitmap = RPG::Cache.picture("Wheel5")
   when 18
     self.bitmap = RPG::Cache.picture("Wheel6")
   when 19
     self.bitmap = RPG::Cache.picture("Wheel7")
   when 20
     self.bitmap = RPG::Cache.picture("Wheel8")
   when 21
     self.bitmap = RPG::Cache.picture("Wheel9")
   when 22
     self.bitmap = RPG::Cache.picture("Wheel10")
   when 23
     self.bitmap = RPG::Cache.picture("Wheel11")
   when 24
     self.bitmap = RPG::Cache.picture("Wheel12")
   end
   return
 end
 
 def update
   if $game_time.hour?(24) != @hour
     refresh
   end
 end
end

I hope someone can help.

Peace!
 
You can skip that whole case statement by doing something simpler:
Code:
class Sprite_Wheel < Sprite
  def refresh
    self.bitmap.clear
    @hour = $game_time.hour?(24)
    bitmap = RPG::Cache.picture("Wheel#{@hour % 12 + 1}")
    self.bitmap.blt(0, 0, bitmap, bitmap.rect)
  end
  def update
    super
    refresh if @hour != $game_time.hour?(24)
  end
What a huge line difference ;)
 

OS

Sponsor

That is really helpful, thanks.

I still have a little problem, though. It seems that the script still won't show the "Wheel1" graphic when it is supposed to be called.
 

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