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 load a character sprite

I am making a quest script and I need to know how to load a specific character sprite graphic.
For example in the Actor1 or Actor2 character sheets, how would I load only the front view of the third character?
 
In the script.  I know that there is a Cache.character(filename) thing but each file has like 8 characters on it.  I specifically want to load one character and only one view of that character.
 

khmp

Sponsor

To load the image associated with a character file you would use the following:
Code:
character = RPG::Cache.character('character_filename')

Let's say you wanted to load a specific character sheet of an actor:
Code:
character = RPG::Cache.character($game_party.actors[actor_id].character_name, $game_party.actors[actor_id].character_hue)
Where "actor_id" is id of the actor you want to display.

Now the math to figure out what the first frame of the sheet would be the total width / 4 and the total_height / 4.
Code:
  #--------------------------------------------------------------------------
  # * Draw Graphic
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_actor_graphic(actor, x, y)
    bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
    cw = bitmap.width / 4
    ch = bitmap.height / 4
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  end

Here's a perfect example of its use. That method is inside Window_Base to draw a character graphic to screen.

Good luck with it atoria! :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