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.

Multiple Animations

Hi,

I need a script that lets more than 1 animation be played on the screen at a time. I really dont think I need to give more detail than that. Non-SDK would be great. Thanks.
 
Code:
#==============================================================================
# ** Multiple Animations
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2007-03-06
# SDK : Version 2.0, Part 1
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (2007-03-06)
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to show multiple animation sprites at the same 
#   time. When an animation sprite is created, it is immediately added to an 
#   array of animation sprites. From there, each animation sprite is handeled 
#   the same way the default animation sprite is handeled. This also delays 
#   animations to prevent multiple damages being displayed at once.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Multiple Animations', 'SephirothSpawn', 1, '2007-03-06')
SDK.check_requirements(2, [1])

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Multiple Animations')

#==============================================================================
# ** RPG::Sprite
#==============================================================================

class RPG::Sprite < ::Sprite
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  if @seph_multianim_stack.nil?
    alias_method :seph_multianim_rpgs_init, :initialize
    alias_method :seph_multianim_rpgs_disp, :dispose
    alias_method :seph_multianim_rpgs_updt, :update
    @seph_multianim_stack = true
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(viewport = nil)
    # Original Initialization
    seph_multianim_rpgs_init(viewport)
    # Create Animation Sprite Array
    @_multi_animation_sprites  = []
    @_multi_animation_duration = []
    @_multi_animation_data     = [] 
    # Damage Delay Count
    @_animations_delay_count = 0
    @_animations_pops_coming = []
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    # Original Dispose
    seph_multianim_rpgs_disp
    # Pass Through Multi-Animations Sprites
    @_multi_animation_duration.size.times { dispose_multi_animations }
  end
  #--------------------------------------------------------------------------
  # * Dispose Multi Animations
  #--------------------------------------------------------------------------
  def dispose_multi_animations(index = 0)
    # Get Sprites
    sprites = @_multi_animation_sprites[index]
    # If Non-nil sprites
    unless sprites.nil?
      # Get First Sprite
      sprite = sprites[0]
      unless sprite.nil?
        @@_reference_count[sprite.bitmap] -= 1
        sprite.bitmap.dispose if @@_reference_count[sprite.bitmap] == 0
      end
      for sprite in sprites
        sprite.dispose
      end
      @_multi_animation_sprites[index] = nil
      @_multi_animation_duration[index] = 0
      @_multi_animation_data[index] = []
    end    
  end
  #--------------------------------------------------------------------------
  # * Animation
  #--------------------------------------------------------------------------
  def animation(animation, hit)
    # Adds Animation to Pop List
    unless animation.nil? && hit.nil?
      @_animations_pops_coming << [animation, hit]  
    end
    # Return If Animation Delay
    return if @_animations_delay_count > 0
    # Start Animation Count
    @_animations_delay_count = 8
    # Gets Pops Coming
    animation, hit = *@_animations_pops_coming.shift
    # Return if Nil Animation
    return if animation.nil?
    # Sets Animation & Hit Data
    @_multi_animation_data << [animation, hit]
    # Set Animation Duration
    @_multi_animation_duration << animation.frame_max
    # Create Sprites
    animation_name = animation.animation_name
    animation_hue = animation.animation_hue
    bitmap = RPG::Cache.animation(animation_name, animation_hue)
    @@_reference_count[bitmap] = 0 unless @@_reference_count.include?(bitmap)
    @@_reference_count[bitmap] += 1
    sprites = []
    if animation.position != 3 or not @@_animations.include?(animation)
      for i in 0..15
        sprite = ::Sprite.new(self.viewport)
        sprite.bitmap, sprite.visible = bitmap, false
        sprites.push(sprite)
      end
    end
    # Add Animation Sprites
    @_multi_animation_sprites << sprites
    # Update Multi Animation
    update_multi_animation(@_multi_animation_data.size - 1)
  end  
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If Animation Delaying
    if @_animations_delay_count > 0
      @_animations_delay_count -= 1
    # If Animation Not Delaying
    else
      # If Animation Waiting to Be Popped
      if @_animations_pops_coming.size > 0
        # Create Animation Sprite
        animation(nil, nil)
      end
    end
    # Original Update
    seph_multianim_rpgs_updt
    # If Animation Sprites Exist & Frame Reset
    if @_multi_animation_duration.size > 0 && Graphics.frame_count % 2 == 0
      # Update Multi-animations
      update_multi_animations  
    end    
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Multi-Animations
  #--------------------------------------------------------------------------
  def update_multi_animations
    # Pass Through All Animation Data
    for i in 0...@_multi_animation_duration.size
      # Decrease Animation Duration
      @_multi_animation_duration[i] -= 1 rescue p @_multi_animation_duration, i
      # Update Multi Animation
      update_multi_animation(i)
    end
    # Deletes Nil Elements
    for index in 0...@_multi_animation_duration.size
      if @_multi_animation_sprites[index].nil? && 
         @_multi_animation_duration[index] == 0 &&
         @_multi_animation_data[index] == []
        @_multi_animation_sprites.delete_at(index)
        @_multi_animation_duration.delete_at(index)
        @_multi_animation_data.delete_at(index)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Multi-Animation
  #--------------------------------------------------------------------------
  def update_multi_animation(i = 0)
    # If Duraction Greater Than 0
    if @_multi_animation_duration[i] > 0
      # Get Animation Data
      anim, hit = *@_multi_animation_data[i]
      # Get Sprites, Cell Data & Position
      sprites   = @_multi_animation_sprites[i]
      frame_index = anim.frame_max -  @_multi_animation_duration[i]
      cell_data = anim.frames[frame_index].cell_data
      position  = anim.position
      # Processes Animation Sprites
      animation_set_sprites(sprites, cell_data, position)
      # Pass Through Timings
      for timing in anim.timings
        # If Frame Index
        if timing.frame == frame_index
          # Processing Animation Timing
          animation_process_timing(timing, hit)
        end
      end
    # If 0 Duration
    else
      dispose_multi_animations(i)
    end
  end
end
#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end

All It requires is SDK Part I so It shouldn't mess with your non SDK scripts
 

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