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.

Short Stop

I just recently made a little piece of code that would animate an icon based on 3 animation sprites and 1 still sprite once done.
I made a code that works perfectly. It animates neatly and just the way I want it to, but as you can see, the animation is handled with updating of the graphics inside the method, causing the player and everything else on the map to halt for like half a second every time the animation is run.

So I tried calling this based on the frame index it's on. The code I use is below, note that the other draw_* methods are of no relevance to the rest.
Code:
class Window_Base
  def draw_action_button(changed = false)
    # Set coordinates
    x = 360
    y = 4
    if @index > 3
      @index = 0
      changed = false
    end
    # If changed: play small animation
    if changed or @index > 0
      i = @index - 1
      # per index: output different image
      bitmap = RPG::Cache.picture("Action Button_" + i.to_s)
      self.contents.blt(x, y, bitmap, Rect.new(0, 0, 64, 64), 255)
      delay = 10
      # Update the graphics
      Graphics.update
      # Clear the HUD
      self.contents.clear
      @index += 1
      # If changed: set action text to new
      if changed
        $game_system.action_text = $game_system.new_action
      end
      # Update map
      $game_map.update
    else
      # Make the new action button
      bitmap = RPG::Cache.picture("Action Button")
      self.contents.blt(x, y, bitmap, Rect.new(0, 0, 64, 64), 255)
      # Draw action text (centered)
      self.contents.font.outline = true
      self.contents.font.size = 14
      self.contents.draw_text(x, y + 13, 64, 32, $game_system.action_text, 1)
      self.contents.font.size = 20
    end
  end
end
Code:
#==============================================================================
# ** Window_HUD
#------------------------------------------------------------------------------
#  This window shows the HUD.
#==============================================================================

class Window_HUD < Window_Base
  attr_accessor :need_refresh
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 480)
    @index = 0
    @need_refresh = true
    self.visible  = true
    self.opacity  = 0
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end

  def refresh
    if $game_system.show_hud and $game_screen.pictures[1].name == ""
      self.visible = true
    else
      self.visible = false
    end
    if $game_system.show_hud and $game_screen.pictures[1].name == ""
      actor = $game_party.actors[0]
      c = $game_system.action_changed? or @index > 0
      if c
        @need_refresh = true
      end
      if @need_refresh
        self.contents.clear
        draw_hearts(0, 0, actor)
        draw_weapon_button
        draw_item_buttons
        draw_money
        draw_keys if $game_switches[12]
        if $game_system.action_changed?
            @index = 1
        end
        draw_action_button(c)
        if c
          draw_hearts(0, 0, actor)
          draw_weapon_button
          draw_item_buttons
          draw_money
          draw_keys if $game_switches[12]
        end
      end
      @need_refresh = false
      self.contents.font.outline = false
    end
    return
  end
end
The picture check is when I am using letterboxes, the HUD will disappear.

Anyway, I guess this is very simple. Do you appear to see an obvious reason why the map halts whenever the animation is to be run?
The 'action_changed?' method is based on a Game_System modification with these methods:
Code:
# Game_System modification
class Game_System
  alias system_int initialize
  
  def initialize
    system_int
    @action_text = ""
    @new_action  = ""
  end
  
  def action_text=(value)
    @action_text = value
    if $scene.is_a?(Scene_Map)
      $scene.hud.refresh
    end
  end
  
  def new_action=(value)
    @new_action = value
    if $scene.is_a?(Scene_Map)
      $scene.hud.refresh
    end
  end
  
  def action_text
    return @action_text
  end
  
  def new_action
    return @new_action
  end
  
  def action_changed?
    return @action_text != @new_action
  end
end

Any help is greatly appreciated. Thanks in advance!

EDIT: I can't believe I posted this here. Please move it to RGSS Support... -.-
 

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