Load multiple images but only 1 show up?

Isabella Ava

Veteran
Veteran
Joined
Sep 13, 2016
Messages
635
Reaction score
756
First Language
English
#RPGVXACE
Hi guys,
I really need some help, i tried to modify these code to load multiple images at once but
only the first one will show up. I cannot figure what else to do
I modified create_picture section to push many arguments into create list
Code:
#--------------------------------------------------------------------------
  # ● Create Battler Pictures
  #--------------------------------------------------------------------------   
  def create_battler_pictures
      @battler_pictures = []
      for i in $game_party.battle_members
        #cuongeke print(i.equips[0].id) / .etype_id
        #+9000 if is actor & +3000 if is weapon
          @cData = [i.id + 9000]
          for j in i.equips
            if j
              if j.etype_id == 0
                @cData.push(j.id + 3000)
              else
                @cData.push(j.id)
              end
            end
          end
          print(@cData)
        #===========
          for k in @cData
              @battler_pictures.push(Sprite_Battler_CM.new(nil,k))
          end
      end   
  end
And then initialize method of Sprite_CM for conditions check
Code:
class Sprite_Battler_CM < Sprite
  include MOG_ACTOR_PICTURE_CM
 
  #--------------------------------------------------------------------------
  # ● Initialize cuongeke
  #--------------------------------------------------------------------------
  def initialize(viewport = nil,battler_id = -1)
      super(viewport)
      if battler_id > 9000
        battler_id -= 9000
        filename = "Actor" + battler_id.to_s
      elsif battler_id > 3000 and battler_id < 9000
        battler_id -= 3000
        filename = "Actor" + "_w_" + battler_id.to_s
      else
        filename = "Actor" + "_e_" + battler_id.to_s
      end
      print(filename)
      self.bitmap = Cache.picture(filename) rescue nil
      self.bitmap = Cache.picture("") if self.bitmap == nil
      sc = (Graphics.width / 2)  - (self.bitmap.width / 2) + PICTURE_POSITION[0]
      @size = [self.bitmap.width + PICTURE_POSITION[0] ,sc]     
      self.visible = false ;  self.opacity = 0 ; self.z = PICTURE_PRIORITY_Z
      self.ox = 0 ; self.oy = self.bitmap.height ; self.x = -@size[0]
      self.y = (Graphics.height + 10) + PICTURE_POSITION[1] ; @cm_visible = false   
      @breach_effect = [1.0,0] ; @battler_id = battler_id  ; @active =  false
  end
But only first one get loaded but i want to show all loaded images, please helps (。•́︿•̀。)
Below is the full code
Code:
#==============================================================================
# +++ MOG - ACTOR PICTURE CM  (v2.1) +++
#==============================================================================
# By Moghunter
# https://atelierrgss.wordpress.com/
#==============================================================================
# Apresenta a imagem do personagem durante a seleção de comandos, com efeitos
# animados.
#==============================================================================
# ● Definindo o nome das imagens dos battlers.
#==============================================================================
# 1 - As imagens devem ser gravadas na pasta
#
# GRAPHICS/PICTURES
#
# 2 - Nomeie os  arquivos de imagens da seguinte forma.
#
#
# ACTOR + ID
#
# EG
#
# ACTOR1.png
#
#==============================================================================
# ● Histórico (Version History)
#==============================================================================
# v2.1 - Melhoria na codificação.
# v2.0 - Correção de não atualizar as imagens dos battlers quando se
#        adiciona ou remove um battler no meio da batalha.
#==============================================================================
module MOG_ACTOR_PICTURE_CM
  #Posição da imagem do battler. (Para fazer ajustes)
  PICTURE_POSITION = [0, 0] 
 
  #Definição da opacidade da imagem.
  PICTURE_OPACITY = 255
 
  #Velocidade de deslize
  SLIDE_SPEED = 30
 
  #Ativar o efeito da imagem respirando.
  BREATH_EFFECT = true
 
  #Definição da prioridade  da imagem na tela.
  PICTURE_PRIORITY_Z = 101
end

$imported = {} if $imported.nil?
$imported[:actor_picture_cm] = true

#===============================================================================
# ■ Game Temp
#===============================================================================
class Game_Temp
 
  attr_accessor :bpicture_cm_need_refresh
 
  #--------------------------------------------------------------------------
  # ● Initialize
  #-------------------------------------------------------------------------- 
  alias mog_battler_cm_initialize initialize
  def initialize
      @bpicture_cm_need_refresh = false
      mog_battler_cm_initialize
  end
 
end

#===============================================================================
# ■ Sprite_Battler_CM
#===============================================================================
class Sprite_Battler_CM < Sprite
  include MOG_ACTOR_PICTURE_CM
 
  #--------------------------------------------------------------------------
  # ● Initialize cuongeke
  #-------------------------------------------------------------------------- 
  def initialize(viewport = nil,battler_id = -1)
      super(viewport)
      if battler_id > 9000
        battler_id -= 9000
        filename = "Actor" + battler_id.to_s
      elsif battler_id > 3000 and battler_id < 9000
        battler_id -= 3000
        filename = "Actor" + "_w_" + battler_id.to_s
      else
        filename = "Actor" + "_e_" + battler_id.to_s
      end
      print(filename)
      self.bitmap = Cache.picture(filename) rescue nil
      self.bitmap = Cache.picture("") if self.bitmap == nil
      sc = (Graphics.width / 2)  - (self.bitmap.width / 2) + PICTURE_POSITION[0]
      @size = [self.bitmap.width + PICTURE_POSITION[0] ,sc]     
      self.visible = false ;  self.opacity = 0 ; self.z = PICTURE_PRIORITY_Z
      self.ox = 0 ; self.oy = self.bitmap.height ; self.x = -@size[0]
      self.y = (Graphics.height + 10) + PICTURE_POSITION[1] ; @cm_visible = false   
      @breach_effect = [1.0,0] ; @battler_id = battler_id  ; @active =  false 
  end 
 
  #--------------------------------------------------------------------------
  # ● Dispose
  #-------------------------------------------------------------------------- 
  def dispose
      super
      self.bitmap.dispose
  end
 
  #--------------------------------------------------------------------------
  # ● Update
  #-------------------------------------------------------------------------- 
  def update
      super
      update_slide
  end 
 
  #--------------------------------------------------------------------------
  # ● Active Battler
  #--------------------------------------------------------------------------     
  def active_battler(battler_id)
      @active = @battler_id == battler_id ? true : false
      self.visible = true if @active ; @cm_visible = false if !@active
  end
 
  #--------------------------------------------------------------------------
  # ● Refresh Battler CM
  #--------------------------------------------------------------------------       
  def refresh_battler(cm_visible, battler_index)
      @cm_visible = cm_visible
      active_battler(battler_index)
  end 
 
  #--------------------------------------------------------------------------
  # ● Update Slide
  #-------------------------------------------------------------------------- 
  def update_slide     
      if !@cm_visible
           self.x -= SLIDE_SPEED if self.x > -@size[0]
           self.opacity -= 25
           if self.x <= -@size[0] or self.opacity == 0
              self.visible = false ; self.opacity = 0 ; self.x = -@size[0]
           end   
        else
           self.x += SLIDE_SPEED if self.x < @size[1]
           self.x = @size[1] if self.x > @size[1]
           self.opacity += 10 if self.opacity < PICTURE_OPACITY
           self.opacity = PICTURE_OPACITY if self.opacity > PICTURE_OPACITY
           update_breath_effect
      end         
      self.visible = false if can_force_hide?
  end
 
  #--------------------------------------------------------------------------
  # ● Can Force Hide
  #-------------------------------------------------------------------------- 
  def can_force_hide?
      return true if $game_temp.blitz_commands_phase if $imported[:mog_blitz_commands]
      return true if $game_temp.chain_action_phase if $imported[:mog_active_chain]
      return false
  end
      
  #--------------------------------------------------------------------------
  # ● Update Breath Effect
  #--------------------------------------------------------------------------   
  def update_breath_effect
      return if !BREATH_EFFECT
      @breach_effect[1] += 1
      case @breach_effect[1]
         when 0..30 ; @breach_effect[0] += 0.0004
         when 31..50 ; @breach_effect[0] -= 0.0004
         else ; @breach_effect[1] = 0 ; @breach_effect[0] = 1.truncate
      end
      self.zoom_y = @breach_effect[0]
  end 
 
  #--------------------------------------------------------------------------
  # ● Force Hide
  #--------------------------------------------------------------------------   
  def force_hide
      @cm_visible = false ; self.visible = false ; self.x = -@size[0]
      self.opacity = 0
  end
 
end

#===============================================================================
# ■ Spriteset_Battle
#===============================================================================
class Spriteset_Battle
 
  #--------------------------------------------------------------------------
  # ● Create Actors
  #--------------------------------------------------------------------------   
  alias mog_battler_cm_create_actors create_actors
  def create_actors
      mog_battler_cm_create_actors
      create_battler_pictures
  end
 
  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------   
  alias mog_battler_cm_dispose dispose
  def dispose
      mog_battler_cm_dispose
      dispose_battler_cm
  end 

  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------   
  alias mog_battler_cm_update update
  def update
      mog_battler_cm_update
      update_battler_cm
  end   

  #--------------------------------------------------------------------------
  # ● Create Battler Pictures
  #--------------------------------------------------------------------------   
  def create_battler_pictures
      @battler_pictures = []
      for i in $game_party.battle_members
        #cuongeke print(i.equips[0].id) / .etype_id
        #+9000 if is actor & +3000 if is weapon
          @cData = [i.id + 9000]
          for j in i.equips
            if j
              if j.etype_id == 0
                @cData.push(j.id + 3000)
              else
                @cData.push(j.id)
              end
            end
          end
          print(@cData)
        #===========
          for k in @cData
              @battler_pictures.push(Sprite_Battler_CM.new(nil,k))
          end
      end   
  end   
 
  #--------------------------------------------------------------------------
  # ● Dispose Battler CM
  #--------------------------------------------------------------------------   
  def dispose_battler_cm
      return if @battler_pictures == nil
      @battler_pictures.each {|sprite| sprite.dispose if sprite != nil }
  end 
 
  #--------------------------------------------------------------------------
  # ● Update Battler CM
  #--------------------------------------------------------------------------   
  def update_battler_cm
      refresh_battler_cm if $game_temp.bpicture_cm_need_refresh
      return if @battler_pictures == nil
      @battler_pictures.each {|sprite| sprite.update }
  end   
    
  #--------------------------------------------------------------------------
  # ● Update CM Pictures
  #--------------------------------------------------------------------------     
  def update_cm_picture(cm_visible, battler_index)
      return if @battler_pictures == nil
      @battler_pictures.each {|sprite| sprite.refresh_battler(cm_visible, battler_index) }
  end 
 
  #--------------------------------------------------------------------------
  # ● CM Force Hide
  #--------------------------------------------------------------------------     
  def cm_force_hide
      return if @battler_pictures == nil
      @battler_pictures.each {|sprite| sprite.force_hide }
  end 
    
  #--------------------------------------------------------------------------
  # ● Refresh Battler CM
  #--------------------------------------------------------------------------     
  def refresh_battler_cm
      $game_temp.bpicture_cm_need_refresh = false
      dispose_battler_cm ; create_battler_pictures
  end
 
end

#===============================================================================
# ■ Scene_Battle
#===============================================================================
class Scene_Battle < Scene_Base
 
 if $imported["YEA-CommandEquip"]
 #--------------------------------------------------------------------------
 # * Command Equip
 #--------------------------------------------------------------------------   
  alias mog_yfcm_command_equip command_equip
  def command_equip
      @spriteset.cm_force_hide
      mog_yfcm_command_equip
  end
  end 
 
  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------       
  alias mog_cm_picture_update_basic update_basic
  def update_basic
      mog_cm_picture_update_basic
      update_picture_visible
  end 
 
  #--------------------------------------------------------------------------
  # ● Update Battler CM Active
  #--------------------------------------------------------------------------     
  def update_picture_visible
      return if @actor_command_window.nil?
      cm_visible = can_cm_picture_visible?     
      cm_id = BattleManager.actor.id rescue -1
      @spriteset.update_cm_picture(cm_visible, cm_id)
  end 
 
  #--------------------------------------------------------------------------
  # ● Can CM Picture Visible
  #--------------------------------------------------------------------------       
  def can_cm_picture_visible?
      if $imported[:mog_atb_system]
          return false if $game_system.atb_type != 0
          return false if $game_message.visible
          return false if $game_temp.battle_end
          return false if $game_temp.end_phase_duration[1] > 0
      end
      return false if $imported[:mog_active_chain] and $game_temp.active_chain 
      return false if $imported[:mog_blitz_commands] and $game_temp.blitz_commands_phase
      return false if @party_command_window.active
      return false if BattleManager.actor.nil?
      return false if @actor_window.active
      return false if @enemy_window.active
      return true if @actor_command_window.active
      return true if @item_window.active
      return true if @skill_window.active
      return false
  end 
 
end

#==============================================================================
# ** Game Interpreter
#==============================================================================
class Game_Interpreter
 
 #--------------------------------------------------------------------------
 # ● Command_129
 #--------------------------------------------------------------------------
 alias mog_bpic_cm_command_129 command_129
 def command_129
     mog_bpic_cm_command_129
     $game_temp.bpicture_cm_need_refresh = true if SceneManager.scene_is?(Scene_Battle)
 end
 
 #--------------------------------------------------------------------------
 # ● Command 335
 #--------------------------------------------------------------------------
 alias mog_bpic_cm_command_335 command_335
 def command_335
     mog_bpic_cm_command_335
     $game_temp.bpicture_cm_need_refresh = true if SceneManager.scene_is?(Scene_Battle)
 end
 
end

#==============================================================================
# ** Game Party
#==============================================================================
class Game_Party < Game_Unit
    
 #--------------------------------------------------------------------------
 # ● Swap Order
 #--------------------------------------------------------------------------
 alias mog_bpic_cm_swap_order swap_order
 def swap_order(index1, index2)
      mog_bpic_cm_swap_order(index1, index2)
      $game_temp.bpicture_cm_need_refresh = true if SceneManager.scene_is?(Scene_Battle)
 end 
 
end
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
4,863
Reaction score
5,538
First Language
Indonesian
Primarily Uses
RMVXA
Here is the debugging tip I could give it to you as I don't think I will be able to test this.
First, make sure if the battler_pictures size exactly has the size you were expecting.

Like putting this on the end of create_battler_pictures
Code:
puts @battler_pictures.size
If it doesn't have the exact size you were expecting, then there might be something wrong with the loop.
The loop honestly pretty clear although I'm not sure what you were trying to do.

If it exactly has the size you were expecting, make sure it has actually had the image for each individual sprites.
In order to do that, you have to remove your failsafe method by removing the keyword "rescue".
These lines
Code:
self.bitmap = Cache.picture(filename) rescue nil
self.bitmap = Cache.picture("") if self.bitmap == nil
Become this
Code:
self.bitmap = Cache.picture(filename)
The failsafe function replace any load error with an empty image. Perhaps you write the filename wrong.
Or for debugging sake, you could try to load a test image to test if the sprite is actually created. For example.
Code:
self.bitmap = Cache.battler("Slime")
Good luck!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

The new intro Logo for my videos.

I speed it up, the one I use to use was to long.
The workweek is now over. Now I can work on my GamZzzzzZzzzzZzzzZzzZz....
Just watched Onward with the family. One of the best movies I've ever seen. <3
2 hours & 20 minutes remaining. :D
...trying to hurry finish up all commissions before I never put the controller down again ;)

Forum statistics

Threads
95,822
Messages
932,185
Members
126,254
Latest member
YKJordan
Top