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.
[VXA] Animated Parallax 1.0

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Animated Parallax
Version: 1.0
Author: modern algebra
Date: December 20, 2011

Version History


  • <Version 1.0> 2011.12.20 - Original Release

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

  • Allows you to animate parallaxes, making it especially useful for parallax mapping
  • Through a simple naming convention, you can have unlimited panels to the parallaxes
  • Can directly set the speed each panel is shown

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


  • modern algebra

Support


Please post in this topic at RMRK for support.

***
Rep:
Level 77
RMRK Junior
It animates, but how would I fix it to the map?

****
Rep:
Level 71
With some thing like this.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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?

****
Bitch
Rep:
Level 87
Bits'n'Pixels
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 :)

***
Rep:
Level 69
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.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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.

***
Rep:
Level 69
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.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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.

**
Rep:
Level 71
Super Maker
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.
The Maker of Battle Dungeons!!


Spoiler for Big ass signature, bro:
AbsoluteIce I finally say your Sig.

Get by 20 attack Dogs...seriously. I got 20 attack Dogs.

*Your signature was raped changed for taking up too much room.
~Sincerely, a staff member. That is all you need to know. That, and I am no one to be trifled with.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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.

**
Rep: +0/-0Level 39
RMRK Junior
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?

**
Rep: +0/-0Level 39
RMRK Junior
Can someone help me out with this?

*
Rep:
Level 85
I am the wood of my broom
2010 Project of the YearProject of the Month winner for January 2010Project of the Month winner for January 2009Project of the Month winner for April 2010
I just want to bump for the same inquiry >w<)/


*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
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
« Last Edit: April 27, 2014, 11:25:13 PM by Exhydra »

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
Rep:
Level 85
I am the wood of my broom
2010 Project of the YearProject of the Month winner for January 2010Project of the Month winner for January 2009Project of the Month winner for April 2010
Thank you very much <3


*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Thanks Exhydra