The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: modern algebra on December 21, 2011, 02:33:27 AM

Title: [VXA] Animated Parallax 1.0
Post by: modern algebra on December 21, 2011, 02:33:27 AM
Animated Parallax
Version: 1.0
Author: modern algebra
Date: December 20, 2011

Version History



Description


This script allows you to set an animated parallax background by having multiple frames and switching between them at a user-defined speed. By default, this script only supports .png, .jpg, and .bmp file formats for the animated parallax panels (as they are the only ones I know RMVX supports).

Features


Instructions

Paste this script into its own slot in the Script Editor, above Main and below Materials. For maximum compatibility, you should also place it below any other custom scripts you have.

Please see the header of the script for more detailed instructions.

Script


Code: [Select]
#==============================================================================
#    Animated Parallax [VXA]
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: December 20, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to set an animated parallax background by having
#   multiple frames and switching between them at a user-defined speed. By
#   default, this script only supports .png, .jpg, and .bmp file formats for
#   the animated parallax panels (as they are the only ones I know RMVX Ace
#   supports).
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#   
#     The script operates by having multiple parallax backgrounds and switching
#    between them at a speed set by you, unique for each map
#
#     Thus, if you want to use an animated parallax, you need to do a few things:
#      (a) Make or find the parallax backgrounds you want to use and import
#        them into your game. Then, label them all the same with the one
#        distinction that at the end of each should have a _1, _2, etc...
#          Example Naming:
#            BlueSky_1, BlueSky_2, BlueSky_3, etc...
#      (b) Set the parallax background to any given map that you want the
#        animated parallaxes for. Be sure to set it to the first one you want
#        in succession, so BlueSky_1, not BlueSky_2 or _3. If you do set it to
#        BlueSky_2, then it will only animate between images _2 and _3.
#      (c) Scroll down to the EDITABLE REGION at line 83 and follow the
#        instructions for setting the animation speed
#``````````````````````````````````````````````````````````````````````````````
#     If you need to change the speed at which parallax panels cycle (for
#    instance, if you have also changed the parallax that is displaying), you 
#    can do so by using the following code in a Script call:
#
#      change_parallax_animation_speed(x)
#        x: the number of frames before cycling to the next panel. There are 60
#          frames in one second.
#
#    Note: there cannot be a space between speed and (.
#      change_parallax_animation_speed(x)     <- Correct
#      change_parallax_animation_speed (x)    <- Incorrect
#
#    You can also change it to an array of times, such that you can make it so
#   some frames remain up for longer than others. To do so, just place all of
#   the speeds for each panel in order, separated by commas. Ie.
#
#      change_parallax_animation_speed(x1, x2, ..., xn)
#
#    The same rule as at line 41 applies.
#
#    EXAMPLES:
#
#      change_parallax_animation_speed(30)
#        Each parallax panel will be up for half a second before switching.
#
#      change_parallax_animation_speed(15, 30, 60, 45)
#        The first parallax panel will be up for one quarter of a second before
#       switching to the second panel; the second panel will be up for half a
#       second before switching to the third panel; the third panel will be up
#       for one second before switching to the fourth panel; the fourth panel
#       will be up for three quarters of a second before switching back to the
#       first panel. Repeat.
#==============================================================================

$imported = {} unless $imported
$imported[:MA_AnimatedParallax] = true

#==============================================================================
# ** Game Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new constants - MAAP_PARALLAX_ANIMATION_FRAMES; MAAP_PRELOAD_PARALLAXES
#      MAAP_SUPPORTED_EXTENSIONS
#    aliased methods - setup_parallax; change_parallax; update_parallax
#    new methods - setup_parallax_frames; maap_check_extensions
#==============================================================================

class Game_Map
  MAAP_PARALLAX_ANIMATION_FRAMES = { # <- Don't touch
  #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  #    EDITABLE REGION
  #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  #  MAAP_PARALLAX_ANIMATION_FRAMES - this constant allows you to set the
  # speed at which the parallax switches to the next graphic in the animation
  # series by individual maps. So if you want it to be every 20 frames in one
  # map but every 35 in another map, this is where you do it. All you need to
  # do is type in the following code:
  #
  #      map_id => frames,
  #
  # where map_id is the ID of the Map you want to set it for and frames is
  # either (a) an integer for how many frames you want to show each panel
  # before switching to the next; or (b) an array of integers where each entry
  # of the array is the number of frames to keep the corresponding frame up
  # before switching to the next. This allows you to vary the time each of the
  # frames is left on before switching. There are 60 frames in a second.
  #
  #    EXAMPLES:
  #      1 => 35,    Map 1 will cycle through parallax panels every 35 frames
  #      2 => 40,    Map 2 will cycle through parallax panels every 40 frames
  #      8 => [20, 5, 15],    Map 8 will keep the first panel of the animated
  #                  parallax on for 20 frames before switching to the second
  #                  panel which will be on for 5 frames before switching to
  #                  the third panel which is on 15 frames before switching
  #                  back to the first panel. Repeat.
  #
  #  Note that the comma is necessary! For any maps where you use animated
  # parallaxes but do not include the map ID in this hash, then it will default
  # to the value set below at: MAAP_PARALLAX_ANIMATION_FRAMES.default.
    1 => 20,
    8 => 40,
  } # <- Don't touch
  #  Changing the below value allows you to change the default speed of frame
  # animation. Ie. the speed of frame animation in a map in which you have not
  # directly set the speed via the above hash configuration.
  MAAP_PARALLAX_ANIMATION_FRAMES.default = 30
  #  Depending on the size of the parallaxes and how many panels you use in a
  # map, there can be some lag when you load new panels. The following option
  # allows you to decide whether all the parallax frames are loaded at once
  # when the map is first entered or individually the first time each panel
  # shows up. Generally, if your panels are very large (1MB+) then you should
  # set it to true; if smaller files, then you should set it to false.
  MAAP_PRELOAD_PARALLAXES = true
  #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  #    END EDITABLE REGION
  #///////////////////////////////////////////////////////////////////////////
  MAAP_SUPPORTED_EXTENSIONS = ["png", "jpg", "bmp"]
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_anmp_setuplax_6id3 setup_parallax
  def setup_parallax(*args, &block)
    ma_anmp_setuplax_6id3(*args, &block) # Run Original Method
    setup_parallax_frames
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Change Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias moda_ap_chngprlx_8uz2 change_parallax
  def change_parallax(*args, &block)
    moda_ap_chngprlx_8uz2(*args, &block) # Run Original Method
    setup_parallax_frames
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maba_ap_updprx_9hv3 update_parallax
  def update_parallax(*args, &block)
    maba_ap_updprx_9hv3(*args, &block) # Run Original Method
    # Use the timer if the parallax has more than one frame
    if @maap_parallax_frames && @maap_parallax_frames.size > 1
      @maap_parallax_frame_timer += 1
      # Check if timer exceeded
      if @maap_parallax_frame_timer >= @maap_frame_speed
        @maap_parallax_frame_timer = 0 # Reset Timer
        # Set parallax to next frame
        @maap_parallax_index = (@maap_parallax_index + 1) % @maap_parallax_frames.size
        @parallax_name = @maap_parallax_frames[@maap_parallax_index]
        set_parallax_frame_speed(@maap_parallax_speed, @maap_parallax_index)
      end
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Parallax Animation Speed
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def set_parallax_frame_speed(parallax_speed = MAAP_PARALLAX_ANIMATION_FRAMES[@map_id], frame = 0)
    @maap_parallax_speed = parallax_speed
    if @maap_parallax_speed.is_a?(Array)
      @maap_frame_speed = [@maap_parallax_speed[frame], @maap_parallax_speed.compact[0]].compact[0]
    else
      @maap_frame_speed = @maap_parallax_speed
    end
    # Get the default setting, in case the time limit is incorrectly set
    unless @maap_frame_speed.is_a?(Integer)
      p "Error: Animated Parallax 1.0\nFrame Speed incorrectly set for #{@map_id}, frame #{frame + 1} - #{@parallax_name}"
      @maap_frame_speed = MAAP_PARALLAX_ANIMATION_FRAMES.default
      @maap_frame_speed = default.compact[0] if @maap_frame_speed.is_a?(Array)
      @maap_frame_speed = 30 if !@maap_frame_speed
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup Parallax Frames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def setup_parallax_frames
    # Retain the names of old map's parallax, for disposal
    last_map_bmps = @maap_parallax_frames.nil? ? [] : @maap_parallax_frames
    # Initialize Data
    @maap_parallax_index = 0
    @maap_parallax_frames = [@parallax_name]
    @maap_parallax_frame_timer = 0
    set_parallax_frame_speed
    # Collect all frames of the parallax animation
    if @parallax_name[/_(\d+)$/] != nil
      frame_id = $1.to_i + 1
      base_name = @parallax_name.sub(/_\d+$/, "")
      while maap_check_extensions("Graphics/Parallaxes/#{base_name}_#{frame_id}")
        @maap_parallax_frames.push("#{base_name}_#{frame_id}")
        frame_id += 1
      end
    end
    # Dispose the cached bitmaps from the previous map
    (last_map_bmps - @maap_parallax_frames).each { |bmp| (Cache.parallax(bmp)).dispose }
    # Preload all the parallax bitmaps so no lag is experienced on first load
    if MAAP_PRELOAD_PARALLAXES
      (@maap_parallax_frames - last_map_bmps).each { |bmp| Cache.parallax(bmp) }
    end
    Graphics.frame_reset
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Check Extensions
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maap_check_extensions (filepath)
    MAAP_SUPPORTED_EXTENSIONS.any? { |ext| FileTest.exist?("#{filepath}.#{ext}") }
  end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - change_parallax_animation_speed
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Change Parallax Animation Speed
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def change_parallax_animation_speed(*args)
    if args.size <= 1
      $game_map.set_parallax_frame_speed(*args)
    else
      $game_map.set_parallax_frame_speed(args)
    end
  end
end

#==============================================================================
# ** Spriteset Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - update_parallax
#==============================================================================

class Spriteset_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_animpara_updlax_7ig8 update_parallax
  def update_parallax(*args, &block)
    # Don't ever dispose the cached parallax pictures.
    @parallax.bitmap = nil if @parallax_name != $game_map.parallax_name 
    ma_animpara_updlax_7ig8(*args, &block) # Run Original Method
  end
end

Credit



Support


Please post in this topic at RMRK for support.
Title: Re: [VXA] Animated Parallax 1.0
Post by: Wiimeiser on March 25, 2012, 05:00:39 AM
It animates, but how would I fix it to the map?
Title: Re: [VXA] Animated Parallax 1.0
Post by: DoctorTodd on March 25, 2012, 05:53:01 AM
With some thing like this (http://yanflychannel.wordpress.com/rmvxa/utility-scripts/parallax-lock/).
Title: Re: [VXA] Animated Parallax 1.0
Post by: modern algebra on March 25, 2012, 01:45:49 PM
I'm not entirely sure why you would need it.

Couldn't you just select the Loop Horizontal and Loop Vertical boxes and leave the Autoscroll at 0?
Title: Re: [VXA] Animated Parallax 1.0
Post by: Brady on June 27, 2012, 05:04:04 PM
Just out of sake of keeping you updated, I'm not sure if you know or not, but there's some compatibility issues between this and Victors "step sounds" script.  No idea why myself, and I'm happy to just have the one, but thought you'd like to know :)
Title: Re: [VXA] Animated Parallax 1.0
Post by: Tuomo L on August 05, 2012, 07:35:48 PM
It seems it makes weird jumps when it goes back to first frame.  :o


It becomes especially noticable if you put it every single frame to change.
Title: Re: [VXA] Animated Parallax 1.0
Post by: modern algebra on August 06, 2012, 06:30:07 PM
I don't really know what you mean by "weird jumps." Is the position changing? Is it just that it is too quick? I would need to see what you mean before I can look into it.
Title: Re: [VXA] Animated Parallax 1.0
Post by: Tuomo L on August 07, 2012, 08:16:47 AM
After reaching the end of the last frame it has a "jump" when it resets the cycle back to the first one. As in, you can tell it reached the first frame instad of it being fluid continuous animation.
Title: Re: [VXA] Animated Parallax 1.0
Post by: modern algebra on August 08, 2012, 10:13:43 PM
That sounds like it is just a disparity between the chosen graphics and not a script problem. By that I mean that it sounds like the problem is that the last frame and the first frame don't animate smoothly because there is not a satisfactory intermediary picture between the two frames. I'm not sure how I could fix that with a script - it sounds like you just need to use smoother transitions between the pictures.

Sorry if that isn't what you mean.
Title: Re: [VXA] Animated Parallax 1.0
Post by: ShinGamix on December 08, 2013, 02:08:38 AM
Is this the same as the VX animated parallax where the demo had the train and trees Modern Algerbra? I loved that script on VX.
Title: Re: [VXA] Animated Parallax 1.0
Post by: modern algebra on January 01, 2014, 06:08:58 PM
I don't remember a train or trees. I don't think I made a demo for it. Someone else might have though.

Sorry for the late response.
Title: Re: [VXA] Animated Parallax 1.0
Post by: Candacis on February 15, 2014, 08:51:40 PM
Hey, I noticed that this script doesn't work in an encrypted file. It works fine in my normal play testing, but as soon as I compress and encrypt the game and start it encrypted, the parallax are not animated anymore. Is there a way to solve this?
Title: Re: [VXA] Animated Parallax 1.0
Post by: Candacis on March 16, 2014, 08:20:32 PM
Can someone help me out with this?
Title: Re: [VXA] Animated Parallax 1.0
Post by: Nessiah on April 27, 2014, 06:23:35 PM
I just want to bump for the same inquiry >w<)/
Title: Re: [VXA] Animated Parallax 1.0
Post by: exhydra on April 27, 2014, 07:31:20 PM
The script uses 'FileTest' to check to see if certain graphics files exist, but that method cannot check paths within encrypted files. I altered the script to allow for such.

Unfortunately, the only method for checking the existence of encrypted graphics files is to try and load the file into memory, which might cause a brief or lengthy slow down depending on how many frames of animation are being used and how large the parallax is.

Code: [Select]
#==============================================================================
#    Animated Parallax [VXA]
#    Version: 1.1
#    Author: modern algebra (rmrk.net)
#    Date: December 20, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to set an animated parallax background by having
#   multiple frames and switching between them at a user-defined speed. By
#   default, this script only supports .png, .jpg, and .bmp file formats for
#   the animated parallax panels (as they are the only ones I know RMVX Ace
#   supports).
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#   
#     The script operates by having multiple parallax backgrounds and switching
#    between them at a speed set by you, unique for each map
#
#     Thus, if you want to use an animated parallax, you need to do a few things:
#      (a) Make or find the parallax backgrounds you want to use and import
#        them into your game. Then, label them all the same with the one
#        distinction that at the end of each should have a _1, _2, etc...
#          Example Naming:
#            BlueSky_1, BlueSky_2, BlueSky_3, etc...
#      (b) Set the parallax background to any given map that you want the
#        animated parallaxes for. Be sure to set it to the first one you want
#        in succession, so BlueSky_1, not BlueSky_2 or _3. If you do set it to
#        BlueSky_2, then it will only animate between images _2 and _3.
#      (c) Scroll down to the EDITABLE REGION at line 83 and follow the
#        instructions for setting the animation speed
#``````````````````````````````````````````````````````````````````````````````
#     If you need to change the speed at which parallax panels cycle (for
#    instance, if you have also changed the parallax that is displaying), you 
#    can do so by using the following code in a Script call:
#
#      change_parallax_animation_speed(x)
#        x: the number of frames before cycling to the next panel. There are 60
#          frames in one second.
#
#    Note: there cannot be a space between speed and (.
#      change_parallax_animation_speed(x)     <- Correct
#      change_parallax_animation_speed (x)    <- Incorrect
#
#    You can also change it to an array of times, such that you can make it so
#   some frames remain up for longer than others. To do so, just place all of
#   the speeds for each panel in order, separated by commas. Ie.
#
#      change_parallax_animation_speed(x1, x2, ..., xn)
#
#    The same rule as at line 41 applies.
#
#    EXAMPLES:
#
#      change_parallax_animation_speed(30)
#        Each parallax panel will be up for half a second before switching.
#
#      change_parallax_animation_speed(15, 30, 60, 45)
#        The first parallax panel will be up for one quarter of a second before
#       switching to the second panel; the second panel will be up for half a
#       second before switching to the third panel; the third panel will be up
#       for one second before switching to the fourth panel; the fourth panel
#       will be up for three quarters of a second before switching back to the
#       first panel. Repeat.
#==============================================================================

$imported = {} unless $imported
$imported[:MA_AnimatedParallax] = true

#==============================================================================
# ** Game Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new constants - MAAP_PARALLAX_ANIMATION_FRAMES; MAAP_PRELOAD_PARALLAXES
#      MAAP_SUPPORTED_EXTENSIONS
#    aliased methods - setup_parallax; change_parallax; update_parallax
#    new methods - setup_parallax_frames; maap_check_extensions
#==============================================================================

class Game_Map
  MAAP_PARALLAX_ANIMATION_FRAMES = { # <- Don't touch
  #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  #    EDITABLE REGION
  #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  #  MAAP_PARALLAX_ANIMATION_FRAMES - this constant allows you to set the
  # speed at which the parallax switches to the next graphic in the animation
  # series by individual maps. So if you want it to be every 20 frames in one
  # map but every 35 in another map, this is where you do it. All you need to
  # do is type in the following code:
  #
  #      map_id => frames,
  #
  # where map_id is the ID of the Map you want to set it for and frames is
  # either (a) an integer for how many frames you want to show each panel
  # before switching to the next; or (b) an array of integers where each entry
  # of the array is the number of frames to keep the corresponding frame up
  # before switching to the next. This allows you to vary the time each of the
  # frames is left on before switching. There are 60 frames in a second.
  #
  #    EXAMPLES:
  #      1 => 35,    Map 1 will cycle through parallax panels every 35 frames
  #      2 => 40,    Map 2 will cycle through parallax panels every 40 frames
  #      8 => [20, 5, 15],    Map 8 will keep the first panel of the animated
  #                  parallax on for 20 frames before switching to the second
  #                  panel which will be on for 5 frames before switching to
  #                  the third panel which is on 15 frames before switching
  #                  back to the first panel. Repeat.
  #
  #  Note that the comma is necessary! For any maps where you use animated
  # parallaxes but do not include the map ID in this hash, then it will default
  # to the value set below at: MAAP_PARALLAX_ANIMATION_FRAMES.default.
    1 => 20,
    8 => 40,
  } # <- Don't touch
  #  Changing the below value allows you to change the default speed of frame
  # animation. Ie. the speed of frame animation in a map in which you have not
  # directly set the speed via the above hash configuration.
  MAAP_PARALLAX_ANIMATION_FRAMES.default = 30
  #  Depending on the size of the parallaxes and how many panels you use in a
  # map, there can be some lag when you load new panels. The following option
  # allows you to decide whether all the parallax frames are loaded at once
  # when the map is first entered or individually the first time each panel
  # shows up. Generally, if your panels are very large (1MB+) then you should
  # set it to true; if smaller files, then you should set it to false.
  MAAP_PRELOAD_PARALLAXES = true
  #|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  #    END EDITABLE REGION
  #///////////////////////////////////////////////////////////////////////////
  MAAP_SUPPORTED_EXTENSIONS = ["png", "jpg", "bmp"]
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_anmp_setuplax_6id3 setup_parallax
  def setup_parallax(*args, &block)
    ma_anmp_setuplax_6id3(*args, &block) # Run Original Method
    setup_parallax_frames
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Change Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias moda_ap_chngprlx_8uz2 change_parallax
  def change_parallax(*args, &block)
    moda_ap_chngprlx_8uz2(*args, &block) # Run Original Method
    setup_parallax_frames
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maba_ap_updprx_9hv3 update_parallax
  def update_parallax(*args, &block)
    maba_ap_updprx_9hv3(*args, &block) # Run Original Method
    # Use the timer if the parallax has more than one frame
    if @maap_parallax_frames && @maap_parallax_frames.size > 1
      @maap_parallax_frame_timer += 1
      # Check if timer exceeded
      if @maap_parallax_frame_timer >= @maap_frame_speed
        @maap_parallax_frame_timer = 0 # Reset Timer
        # Set parallax to next frame
        @maap_parallax_index = (@maap_parallax_index + 1) % @maap_parallax_frames.size
        @parallax_name = @maap_parallax_frames[@maap_parallax_index]
        set_parallax_frame_speed(@maap_parallax_speed, @maap_parallax_index)
      end
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Parallax Animation Speed
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def set_parallax_frame_speed(parallax_speed = MAAP_PARALLAX_ANIMATION_FRAMES[@map_id], frame = 0)
    @maap_parallax_speed = parallax_speed
    if @maap_parallax_speed.is_a?(Array)
      @maap_frame_speed = [@maap_parallax_speed[frame], @maap_parallax_speed.compact[0]].compact[0]
    else
      @maap_frame_speed = @maap_parallax_speed
    end
    # Get the default setting, in case the time limit is incorrectly set
    unless @maap_frame_speed.is_a?(Integer)
      p "Error: Animated Parallax 1.0\nFrame Speed incorrectly set for #{@map_id}, frame #{frame + 1} - #{@parallax_name}"
      @maap_frame_speed = MAAP_PARALLAX_ANIMATION_FRAMES.default
      @maap_frame_speed = default.compact[0] if @maap_frame_speed.is_a?(Array)
      @maap_frame_speed = 30 if !@maap_frame_speed
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup Parallax Frames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def setup_parallax_frames
    # Retain the names of old map's parallax, for disposal
    last_map_bmps = @maap_parallax_frames.nil? ? [] : @maap_parallax_frames
    # Initialize Data
    @maap_parallax_index = 0
    @maap_parallax_frames = [@parallax_name]
    @maap_parallax_frame_timer = 0
    set_parallax_frame_speed
    # Collect all frames of the parallax animation
    if @parallax_name[/_(\d+)$/] != nil
      frame_id = $1.to_i + 1
      base_name = @parallax_name.sub(/_\d+$/, "")
      while maap_check_extensions("#{base_name}_#{frame_id}")
        @maap_parallax_frames.push("#{base_name}_#{frame_id}")
        frame_id += 1
      end
    end
    # Dispose the cached bitmaps from the previous map
    (last_map_bmps - @maap_parallax_frames).each { |bmp| (Cache.parallax(bmp)).dispose }
    # Preload all the parallax bitmaps so no lag is experienced on first load
    if MAAP_PRELOAD_PARALLAXES
      (@maap_parallax_frames - last_map_bmps).each { |bmp| Cache.parallax(bmp) }
    end
    Graphics.frame_reset
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Check Extensions
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maap_check_extensions (filepath)

    MAAP_SUPPORTED_EXTENSIONS.any? { |ext| exenc_check_exist("#{filepath}.#{ext}") }
   
  end
 
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Check Files
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def exenc_check_exist (file)

    # Skip loading every bitmap if parallax is located outside the encrypted archive
    return true if FileTest.exist?("Graphics/Parallaxes/" + file)
   
    begin
      # Attempt to load each parallax with any failures getting handled
      Bitmap.new ("Graphics/Parallaxes/" + file)
      return true
    rescue
      return false
    end
   
  end
 
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - change_parallax_animation_speed
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Change Parallax Animation Speed
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def change_parallax_animation_speed(*args)
    if args.size <= 1
      $game_map.set_parallax_frame_speed(*args)
    else
      $game_map.set_parallax_frame_speed(args)
    end
  end
end

#==============================================================================
# ** Spriteset Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - update_parallax
#==============================================================================

class Spriteset_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_animpara_updlax_7ig8 update_parallax
  def update_parallax(*args, &block)
    # Don't ever dispose the cached parallax pictures.
    @parallax.bitmap = nil if @parallax_name != $game_map.parallax_name 
    ma_animpara_updlax_7ig8(*args, &block) # Run Original Method
  end
end
Title: Re: [VXA] Animated Parallax 1.0
Post by: Nessiah on April 28, 2014, 02:34:01 AM
Thank you very much <3
Title: Re: [VXA] Animated Parallax 1.0
Post by: modern algebra on April 28, 2014, 03:14:57 AM
Thanks Exhydra