RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Trouble with animated characters in HUD [VX]

0 Members and 1 Guest are viewing this topic.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Ok, so I've made a simple animated character in my HUD. Every 30 frames, the actor does a stepping animation. It's code (or what part matters) can be found here:

Code: [Select]
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This is a superclass of all windows in the game.
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Draw Battler Character
  #     character_name  : Character graphic filename
  #     character_index : Character graphic index
  #     index : position of character
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_battler_character(character_name, character_index, pos_index, x, y)
    return if character_name == nil
    bitmap = Cache.character(character_name)
    sign = character_name[/^[\!\$]./]
    if sign != nil and sign.include?('$')
      cw = bitmap.width / 3
      ch = bitmap.height / 4
    else
      cw = bitmap.width / 12
      ch = bitmap.height / 8
    end
    n = character_index
    src_rect = Rect.new((n % 4 * 3 + 1) * cw - cw * pos_index, (n / 4 * 4) * ch, cw, ch)
    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  end
end

#==============================================================================
# ** Window_BattleStatus
#------------------------------------------------------------------------------
#  This window displays the status of all party members on the battle screen.
#==============================================================================

class Window_BattleStatus < Window_Selectable
 #--------------------------------------------------------------------------
  # * Object Initialization
  #     x : window X coordinate
  #     y : window Y coordinate
  #--------------------------------------------------------------------------
  alias coz_omhud_bs_initialize initialize
  def initialize
    @char_index = -1
    @frames = 0
    coz_omhud_bs_initialize
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh(pos = 0)
    @pos = pos
    self.contents.clear
    for actor in $game_party.members
      draw_actor_face(actor, 2, actor.index * 96 + 2, 92)
      x = 104
      y = actor.index * 96 + WLH / 2
      draw_actor_name(actor, x, y)
      draw_actor_class(actor, x + 150, y)
      draw_icon(16, x + 126, y)
      draw_actor_level(actor, x, y + WLH * 1)
      draw_actor_state(actor, x, y + WLH * 2)
      draw_actor_hp(actor, x + 150, y + WLH * 1)
      draw_icon(99, x + 126, y + WLH * 1)
      draw_actor_mp(actor, x + 150, y + WLH * 2)
      draw_icon(100, x + 126, y + WLH * 2)
      draw_battler_character(actor.character_name, actor.character_index, @char_index, 48, 94)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    if @pos == 0
      @frames += 1
      if @frames == 30
        if @char_index < 1
          @char_index += 1
          @frames -= 30
          refresh
        else
          @char_index -= 2
          @frames -= 30
          refresh
        end
        if @char_index != 0 and @char_index != 1 and @char_index != -1
          @char_index == -1
        end
        refresh
      end
    elsif @pos == 1
      @frames += 2
      if @frames == 30
        if @char_index < 1
          @char_index += 1
          @frames -= 30
          refresh
        else
          @char_index -= 2
          @frames -= 30
          refresh
        end
        if @char_index != 0 and @char_index != 1 and @char_index != -1
          @char_index == -1
        end
        refresh
      end
    end
  end

The HUD is accompanied by a piece of code that's around 7 lines.

Code: [Select]
  class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Update Party Command Selection
  #--------------------------------------------------------------------------
  alias coz_update_party_command_selection update_party_command_selection
  def update_party_command_selection
    @status_window.refresh(@party_command_window.index)
    coz_update_party_command_selection
  end
end

As you can probably see, the status window (Window_BattleStatus) refreshes according the the party command windows index. Should the player move the cursor to Escape, the actor's graphic should increase his movement from 30 frames per movement to 15 frames per movement. This usually happens, but is sometimes not the case. Sometimes, the actor's graphic may stop moving. I've tried checking if the @char_index is not -1, 0, or 1 (thus the @char_index checking code), but it doesn't seem to be working. I've also tried doing checks with @pos, but that doesn't seem to be working either.

Any ideas?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, it could be that the player is going over Escape at a time when @frames is an odd number. If that happens, then @frames would go from 29 to 31 and never hit 30, and therefore never be refreshed and never be reset, but keep increasing forever. A better way to do it would use a >= check, rather than an == check, and just set @frames to 0 instead of subtracting 30.

Anyway, aside from that, I don't think you should be refreshing the entire window every 15/30 frames just to change the actor position. I would either use a separate sprite or make a separate draw_sprite method that would only clear the rect where the sprite is and redraw there. Since it only happens twice/four times a second, it likely won't make a big difference in lag, but a good general rule to follow is not to do more than is necessary to achieve the result.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
I was experimenting with sprites, but I think I'm going to stick to drawing the sprite through window and refreshing it until I can get more familiar with them.

Anyway, it works fine! Thanks.