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.

Dealing with images

Mea

Member

I wasn't sure whether to post this here or in Script requests. Seeing as it's more of a mechanics question than a straight out "please do me a script question" I guess it belongs here.

I am very much a non-scripter and I'm feeling completely lost in what should be something relatively easy.

I have this script for pictoral indicators
Code:
=begin
#==============================================================================
# ● Tibuda's Pictoral Indicators 
#==============================================================================
=end
#--------------------------------------------------------------------------
# ● Begin SDK Log
#--------------------------------------------------------------------------
SDK.log('Pictoral Indicators', 'Tibuda', 1.0, '3/13/07')
#--------------------------------------------------------------------------
# ● Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1])
#--------------------------------------------------------------------------
# ● Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Pictoral Indicators')
  
class Window_BattleStatus
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  EMPTY_HP_VIAL = 'vial_empty_red'
  EMPTY_SP_VIAL = 'vial_empty_blue'
  HP_VIAL    = 'vial_red'
  SP_VIAL    = 'vial_blue'
  BG    = 'infobg'
  #--------------------------------------------------------------------------
  # * Draw Vial
  #--------------------------------------------------------------------------
  def draw_vial(empty, full, percent, x, y)
    # Get Empty Bitmap
    empty_bitmap = RPG::Cache.picture(empty)
    # Create Destination Rect
    dest_rect = Rect.new(x, y, empty_bitmap.width, empty_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, empty_bitmap, empty_bitmap.rect)
    # Get full Bitmap
    full_bitmap = RPG::Cache.picture(full)
    # Get Width and Height
    width, height = full_bitmap.width, percent * full_bitmap.height / 100
    # Get Difference in height
    diff = full_bitmap.height - height
    # Create Source Rect
    src_rect = Rect.new(0, diff, full_bitmap.width, full_bitmap.height)
    # Create Destination Rect
    dest_rect = Rect.new(x, y + diff, full_bitmap.width, full_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, full_bitmap, src_rect)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw Vial
    draw_vial(EMPTY_HP_VIAL, HP_VIAL, 100 * actor.hp / actor.maxhp, x, y)
    # Draw Hp Text
    self.contents.draw_text(x, y + 40, width, 32, actor.hp.to_s)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #--------------------------------------------------------------------------
  def draw_actor_sp(actor, x, y, width = 144)
    # If Actor Maxsp is greater than 0
    if actor.maxsp > 0
      # Draw Vial
      draw_vial(EMPTY_SP_VIAL, SP_VIAL, 100 * actor.sp / actor.maxsp, x, y)
      # Draw Sp Text
      self.contents.draw_text(x, y + 40, width, 32, actor.sp.to_s)
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Clear Contents
    self.contents.clear
    # Run Through Each Actor With index
    $game_party.actors.each_with_index do |actor, index|
      # Get X coordinate
      actor_x = index * 160 + 4
     # Draws Name
      draw_actor_name(actor, actor_x, -10)
      # Draws Hp (index, x placement, y placement)
      draw_actor_hp(actor, actor_x, 35)
      # Draws Sp
      draw_actor_sp(actor, actor_x + 80, 35)
      # Draw Attack bar
      draw_actor_at(actor, actor_x, 96, 120)
      # If Level Up Flags
      if @level_up_flags[index]
        # Normal Color
        self.contents.font.color = normal_color
        # Level Up
        self.contents.draw_text(actor_x, 120, 120, 32, 'LEVEL UP!')
      end
    end
  end
end
#--------------------------------------------------------------------------
#  End SDK Enabled Check
#--------------------------------------------------------------------------
end

And in battle, the characters are indicated like this:
http://www.stkp.com/rpgmxp/xero/battledata_before.jpg[/img]
Which is nice, but I want to jazz it up a bit and add an image in the background behind the character and move around some of the data so it looks like this:
http://www.stkp.com/rpgmxp/xero/battledata_demo.jpg[/img]

I want to do this myself, but I can't figure out how you deal with adding image objects into a script. I read through one window creation tutorial and felt even more lost than when I started.

Is there someone who can tell me what I'm looking for or the basic mechanics of how RGSS deals with images or something (first "a" then "b" etc.)? I'm feeling very frustrated right now because I keep hitting walls when I try to modify windows, images, and so forth to make things work together better in the scripts I'm using.

Thanks in advance
 
If you want to add a picture to your window, simply use this line of code in your refresh method:
Code:
bitmap = RPG::Cache.picture("picture's name")
self.contents.blt(x, y, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height))

You only have to change the x and y values and replace "picture's name" with the name of your image saved in the Pictures folder.
If you have any question just ask.
 

Mea

Member

That's it? I was under the impression it was a lot more complicated.

(tries it)

That is it! Thank you!

Oh wait... something's cutting off the top and bottom of my images.

Here's what it looks like:
http://www.stkp.com/rpgmxp/xero/prob.jpg[/img]

I can't tell what's chopping them off like that. Does this have something to do with Z-indexing and layering? How does one control that?

Here's the script as it stands with my edit
Code:
=begin
#==============================================================================
# ● Tibuda's Pictoral Indicators 
#==============================================================================
=end
#--------------------------------------------------------------------------
# ● Begin SDK Log
#--------------------------------------------------------------------------
SDK.log('Pictoral Indicators', 'Tibuda', 1.0, '3/13/07')
#--------------------------------------------------------------------------
# ● Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1])
#--------------------------------------------------------------------------
# ● Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Pictoral Indicators')
  
class Window_BattleStatus
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  EMPTY_HP_VIAL = 'vial_empty_red'
  EMPTY_SP_VIAL = 'vial_empty_blue'
  HP_VIAL    = 'vial_red'
  SP_VIAL    = 'vial_blue'
  BG    = 'infobg'
  #--------------------------------------------------------------------------
  # * Draw Vial
  #--------------------------------------------------------------------------
  def draw_vial(empty, full, percent, x, y)
    # Get Empty Bitmap
    empty_bitmap = RPG::Cache.picture(empty)
    # Create Destination Rect
    dest_rect = Rect.new(x, y, empty_bitmap.width, empty_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, empty_bitmap, empty_bitmap.rect)
    # Get full Bitmap
    full_bitmap = RPG::Cache.picture(full)
    # Get Width and Height
    width, height = full_bitmap.width, percent * full_bitmap.height / 100
    # Get Difference in height
    diff = full_bitmap.height - height
    # Create Source Rect
    src_rect = Rect.new(0, diff, full_bitmap.width, full_bitmap.height)
    # Create Destination Rect
    dest_rect = Rect.new(x, y + diff, full_bitmap.width, full_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, full_bitmap, src_rect)
  end
  #
  # Custom Draw Actor Name
  #
  def MEAdraw_actor_name(actor, x, y)
    self.contents.font.size = 18
    self.contents.draw_text(x, y, 120, 32, actor.name,1)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw Vial
    draw_vial(EMPTY_HP_VIAL, HP_VIAL, 100 * actor.hp / actor.maxhp, x, y)
    # Draw Hp Text
    self.contents.draw_text(x-47, y -25, width, 32, actor.hp.to_s,1)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #--------------------------------------------------------------------------
  def draw_actor_sp(actor, x, y, width = 144)
    # If Actor Maxsp is greater than 0
    if actor.maxsp > 0
      # Draw Vial
      draw_vial(EMPTY_SP_VIAL, SP_VIAL, 100 * actor.sp / actor.maxsp, x, y)
      # Draw Sp Text
      self.contents.draw_text(x-45, y -25, width, 32, actor.sp.to_s,1)
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Clear Contents
    self.contents.clear
    # Run Through Each Actor With index
    $game_party.actors.each_with_index do |actor, index|
      # Get X coordinate
      actor_x = index * 160 + 4
      # Draw Background
      bitmap = RPG::Cache.picture("battledatabg")
        self.contents.blt(actor_x-20, -10, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height))
      # Draws Name
      MEAdraw_actor_name(actor, actor_x, -15)
      # Draws Hp (index, x placement, y placement)
      draw_actor_hp(actor, actor_x-15, 45)
      # Draws Sp
      draw_actor_sp(actor, actor_x + 80, 45)
      # Draw Attack bar
      draw_actor_at(actor, actor_x, 104, 120)
      # If Level Up Flags
      if @level_up_flags[index]
        # Normal Color
        self.contents.font.color = normal_color
        # Level Up
        self.contents.draw_text(actor_x, 120, 120, 32, 'LEVEL UP!')
      end
    end
  end
end
#--------------------------------------------------------------------------
#  End SDK Enabled Check
#--------------------------------------------------------------------------
end
 
Haven't tried it, but try adding this in a new window above main:

Code:
class Scene_Battle
  alias raz_fix_battle_main main

  def main
    @sprite = Srite.new
    @sprite.bitmap = RPG::Cache.picture("battledatabg")
    for i in 0...$game_party.actors.size
      @sprite.x = i * 160 + 4
    end
    @sprite.y = 320
    raz_fix_battle_main
    @sprite.dispose
  end
end
 
Hmm... Try this, that should work. Add it below any script you're using and above main.

Code:
class Scene_Battle
  alias raz_fix_battle_main main

  def main
    @sprite = Sprite.new
    @sprite.z = 101
    @sprite.bitmap = RPG::Cache.picture("001-Fighter01")
    for i in 0...$game_party.actors.size
      @sprite.x = i * 160 + 4
    end
    @sprite.y = 320
    raz_fix_battle_main
    @sprite.dispose
  end
end
 

Mea

Member

Sorry Raziel, I haven't had a chance to log in for a while.

I tried it and it keeps asking for "001-Fighter01" for some reason. I see it in the new script but I'm not sure why it's calling it.
 
Whoops, my fault, used it for testing purpose. :p

Code:
class Scene_Battle
  alias raz_fix_battle_main main

  def main
    @sprite = Sprite.new
    @sprite.z = 101
    @sprite.bitmap = RPG::Cache.picture("battledatabg")
    for i in 0...$game_party.actors.size
      @sprite.x = i * 160 + 4
    end
    @sprite.y = 320
    raz_fix_battle_main
    @sprite.dispose
  end
end
 
Well, the failed disposing is quite simple...I think. Try this simple edit:

Code:
class Scene_Battle
  alias raz_fix_battle_main main

  def main
    @sprite = Sprite.new
    @sprite.z = 101
    @sprite.bitmap = RPG::Cache.picture("battledatabg")
    for i in 0...$game_party.actors.size
      @sprite.x = i * 160 + 4
    end
    @sprite.y = 320
    raz_fix_battle_main
    for i in 0...$game_party.actors.size
      @sprite.dispose
    end
  end
end

For the cutting, is simple: the pictures exit from the window.
 

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