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.

Small Question (Drawing Images)

Godot

Member

Yes, a new post that isn't "Hi can you code me an entire game?" :tongue2:

I'm trying to get acquainted with the ol' ruby coding so I was just wondering, how would I have the game draw an image, instead of text, on the menu. Say if I wanted a graphic/icon that said "Lv" rather than just the text in my game, what would I do?

Any and all help appreciated. :smile:
 
Hi Godot,

I'm only a beginner at scripting, but i will try to explain as good as i can  :wink:

To draw an image instead of having a text that says "Lv" on the menu you must go to Window_MenuStatus.
Line 32 is the line that draws the lvl of the actor. so you should remove line 32.

line 32:
Code:
draw_actor_level(actor, x, y + 32)

and instead of line 32, you should put in this:
Code:
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 35, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 32, 120, 32, $game_actors[1].level.to_s, 2)

This will put the "Lv" image where the Lv text used to be and the actual level where it used to be. But this will only draw the image and the level for the first actor.
So you must copy and paste this 3 times (if you have 4 party members) and change the height of the image and the text, and you must also change $game_actors to the actor that you wish to display the level for.
I will try to explain a little bit more what these lines do:

This code will get the the image named Lv from the icon folder:
Code:
bitmap = RPG::Cache.icon('Lv')

This will draw the image, and you can change the x and y position to whatever you want. the 24,24 indicates (right word?)
that the icon is 24x24.
Code:
self.contents.blt(x y, bitmap, Rect.new(0,0,24,24))

This code draws the actual level of the character.
$game_actors[1] gets actor 1 in the database, you can change the number to the actor that should be in the 1 position of the party.
.level gets the level of the actor and .to_s makes it into a string so it can be written.
align is the position of the text. it can either be 0, 1 or 2 (0 = left, 1 = center, 2 = right)
Code:
self.contents.draw_text(x, y, width, height, $game_actors[1].level.to_s, align)


now you need to copy and paste it 3 times,
Code:
    if $game_party.actors.size > 1
      bitmap = RPG::Cache.icon('032-Item01')
      self.contents.blt(62, 153, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 148, 120, 32, $game_actors[2].level.to_s, 2)
    end

The "if $game_party.actors.size > 1"  checks if there are more than 1 actor in the party, if there is, then it will draw the image and the level.You need to change the number + 1 for every paste.
Here is the final code of the whole "Window_MenuStatus":

Code:
#==============================================================================
# ** Window_MenuStatus
#------------------------------------------------------------------------------
#  This window displays party member status on the menu screen.
#==============================================================================

class Window_MenuStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 480, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.active = false
    self.index = -1
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      x = 64
      y = i * 116
      actor = $game_party.actors[i]
      draw_actor_graphic(actor, x - 40, y + 80)
      draw_actor_name(actor, x, y)
      draw_actor_class(actor, x + 144, y)
      if $game_party.actors.size > 0
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 35, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 32, 120, 32, $game_actors[1].level.to_s, 2)
      end
    if $game_party.actors.size > 1
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 153, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 148, 120, 32, $game_actors[2].level.to_s, 2)
    end
    if $game_party.actors.size > 2
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 270, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 265, 120, 32, $game_actors[3].level.to_s, 2)
    end
    if $game_party.actors.size > 3
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 386, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 382, 120, 32, $game_actors[4].level.to_s, 2)
    end
      draw_actor_state(actor, x + 90, y + 32)
      draw_actor_exp(actor, x, y + 64)
      draw_actor_hp(actor, x + 236, y + 32)
      draw_actor_sp(actor, x + 236, y + 64)
    end
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
    end
  end
end

This HAS limitations though, you need to have those 4 part members in the same order that you put them in the script.
so:

Code:
    if $game_party.actors.size > 0
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 35, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 32, 120, 32, $game_actors[1].level.to_s, 2)
    if $game_party.actors.size > 1
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 153, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 148, 120, 32, $game_actors[2].level.to_s, 2)
      end
    end
    if $game_party.actors.size > 2
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 270, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 265, 120, 32, $game_actors[3].level.to_s, 2)
      end
      end
    if $game_party.actors.size > 3
      bitmap = RPG::Cache.icon('Lv')
      self.contents.blt(62, 386, bitmap, Rect.new(0,0,24,24))
      self.contents.draw_text(0, 382, 120, 32, $game_actors[4].level.to_s, 2)
    end

means that actor 1 in the database must be number 1 in the party "$game_actors[1]" number 2 second, number 3 third and number 4 fourth.
But you can of course change the number in "$game_actors[number]" but the first $game_actors[number] must be the first in the party and the last $game_actors[number] must be the last one in the party

And that's it! i hope you understand me. If i made anything unclear just ask me, and i will explain it to you.
There is probably an easier/better way of doing this, but this is what i would have done, but then again, "I'm only a beginner at scripting"
Good luck :thumb:


EDIT: fixed it a little bit, was a bit buggy
 
Okay, i don't know why, but this doesn't work..  but it did work a sec ago :mad:
i must have done something to screw it up o.O
I'll try to fix it.

Edit: works now, i changed it from:

Code:
if $game_party.actors[number]

to:

Code:
if $game_party.actors.size > number

somehow, it didn't work with a fourth "if $game_party.actors[number]"
 

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