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.

How to multiply images[RESOLVED]

Star

Sponsor

Okay lets say I want a graphic to appear as a hud. An HP bar so to say. I know how to measure how much HP and MAXHP a character has. But I want more of the graphic to appear depending on how much Max hp I have. Lets say I have 3 hp, I want three hearts instead of one to appear across. How do I multiply method calls depending on max hp and current hp?

def drawmaphp(maxhp, hp, x, y)
back = RPG::Cache.picture("StrawberryEmpty")
cw = back.width
ch = back.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x, y, back, src_rect)
meter = RPG::Cache.picture("Strawberry")
cw = meter.width
ch = meter.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x, y, meter, src_rect)
end

Then the method call
actor = $game_party.actors[0]
drawmaphp(actor.maxhp, actor.hp, 0, 0)
 

Star

Sponsor

BwdYeti":2tp27wf7 said:
Use a for loop to repeat the blt times the amount of hp (say, for i in 0...hp), and set the x based on the current loop iteration (i * cw).
I knew that was the answer but I couldn't get it to work, but now I did. Thanks for your help, I finally figured out what the for i in 0 meant. It's so much better than tons of if actor.hp == blah blah blah. :thumb:
 

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