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.

Animated Characters in Windows

Culex

Member

I hope this is simple enough...

The Request!
In my menu windows (Window_MenuStatus, Window_Status, etc.), I would like for the characters to walk in place when alive, and be still when dead. I will not provide a screenshot as I feel it is unnecessary.

The Rest...

No fool will establish a request without doing some decent research! I've searched both Google and these forums (searches include animated, animated characters, animated sprites, walking characters, CMS, custom menu system), and they all seem to refer to Minkoff's Battlers. There was an Animated Save File script at the Game Baker site, which I will not post because of his site rules, and I integrated some pieces of that into my other window scripts with awkward results (i.e. the characters are still for a moment and then wiggle for a few seconds?). I deleted all of that garble from my script database, but if need be I'll try to put it back together for you. :D

I would be pleased to work with anyone to make this request possible. If you need more information, feel free to PM me or simply reply to this topic.  :)
 

poccil

Sponsor

The following change to the draw_actor_graphic method in Window_Base will do what you want:

Code:
  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
    frame = (actor.dead?) ? 0 : (Graphics.frame_count/4)%4
    src_rect = Rect.new(cw*frame, 0, cw, ch)
    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  end

Many windows derived from Window_Base or Window_Selectable use the draw_actor_graphic method to draw the character, mostly in its refresh method.  However, refresh is not called every frame, and some scenes don't even call update on the window every frame, either (which would call refresh if necessary.
 

Culex

Member

I followed the instructions without doing anything else and the character remains still. I proceeded to insert @status_window.refresh after @status_window.update in Scene_Menu. It works now, except that its really, really, REALLY laggy; opening up the menu screen takes more time than usual, plus the reaction time for the cursor is delayed and it flashes terrifyingly slow. :P Is there something else I can do with @status_window.refresh or is there a different approach?
 
Code:
class Window_MenuStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # * Moving graphic
  #--------------------------------------------------------------------------
  def refresh_graphic
    for i in 0...$game_party.actors.size
      x = 64
      y = i * 116
      actor = $game_party.actors[i]
      self.contents.fill_rect(0,y,64,116,Color.new(0,0,0,0))
      draw_actor_graphic_moving(actor, x - 40, y + 80)
    end
  end
  def draw_actor_graphic_moving(actor, x, y)
    bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
    cw = bitmap.width / 4
    ch = bitmap.height / 4
    frame = (actor.dead?) ? 0 : (Graphics.frame_count/4)%4
    src_rect = Rect.new(cw*frame, 0, cw, ch)
    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  end
  alias moving_graphic_update update
  def update
    moving_graphic_update
    refresh_graphic
  end
end 

This selectively clears and refreshes only the graphics and shouldn't be laggy. Not the fastest solution yet. It refreshes at every frame and it's not needed.
Also, i'm not sure of the coordinates here (too lazy to read the help now):
Code:
      self.contents.fill_rect(0,y,64,116,Color.new(0,0,0,0))
 
If you have problems with bigger chars, play around with the 4 values...
 

Culex

Member

So far that's the best method. No noticeable lag, but there is one more thing. Upon opening the screen, there is a slight pause before the sprites appear. Is there any way to remedy that? I'm sorry to sound so anal but I'm a quality freak. :D Thank you guys so much for your help so far, by the way!  ;D
 

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