¡Bienvenido a Universo Maker!
¿Es esta la primera vez que visitas el foro? Si es así te recomendamos que te registres para tener completo acceso a todas las áreas y secciones del foro, así también podrás participar activamente en la comunidad. Si ya tienes una cuenta, conectate cuanto antes.
Iniciar Sesión Registrarme

No estás conectado. Conéctate o registrate

Ver el tema anterior Ver el tema siguiente Ir abajo Mensaje [Página 1 de 1.]

#1 Parallax Mapping - VXAce el Lun Mar 07, 2016 11:56 pm

Reputación del mensaje :100% (3 votos)

Vala

avatar
Muy buenas tardes a todos.

Increíblemente yo, sí, yo, les traigo hoy dos scripts para VX Ace que son de gran utilidad a la hora de realizar mapeado por paralaje o "Parallax Mapping".

Para aquellos makeros que aun desconocen esta herramienta, los invito a googlear al respecto, porque estoy completamente segura de que querrán implementarlo en un futuro.

Por supuesto, debo aclarar que ninguno de estos scripts son míos, y deberán dar crédito a sus respectivos autores si desean utilizarlos en sus proyectos.

Por último, les recomiendo que lean las instrucciones de uso que vienen incluidas en los mismos, ya que les servirán para personalizarlos y sacarles el máximo provecho para sus juegos.

Parallax Lock v1.00:
El primero de estos scripts se lo debemos a Yanfly y se trata del "Parallax Lock" que sirve para evitar que la imagen que coloquemos de fondo en el mapa se mueva con el personaje, es decir, para fijar o lockear el parallax. Acá va:

Código:
#==============================================================================
# <lock parallax x>
# <lock parallax y>
# <full lock parallax>
# <tile lock parallax>
#
# ▼ Yanfly Engine Ace - Parallax Lock v1.00
# -- Last Updated: 2012.02.19
# -- Level: Normal
# -- Requires: n/a
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YEA-ParallaxLock"] = true

#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.02.19 - Started Script and Finished.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script gives developers the ability to lock a map's parallax and cause
# it to not scroll by either vertically, horizontally, or both. Furthermore,
# this script also enables tile locking the map parallax, allowing the parallax
# to only move in conjunction with the player.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# -----------------------------------------------------------------------------
# Map Notetags - These notetags go in the map notebox in a map's properties.
# -----------------------------------------------------------------------------
# <lock parallax x>
# This prevents the map's parallax from scrolling horizontally.
#
# <lock parallax y>
# This prevents the map's parallax from scrolling vertically.
#
# <full lock parallax>
# This prevents the map's parallax from scrolling at all.
#
# <tile lock parallax>
# This causes the map's parallax to be locked to tiles and scrolls with them.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
#==============================================================================
# ▼ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================

module YEA
  module REGEXP
  module MAP
    
    LOCK_PARALLAX_X = /<(?:LOCK_PARALLAX_X|lock parallax x)>/i
    LOCK_PARALLAX_Y = /<(?:LOCK_PARALLAX_Y|lock parallax y)>/i
    FULL_LOCK_PARALLAX = /<(?:FULL_LOCK_PARALLAX|full lock parallax)>/i
    TILE_LOCK_PARALLAX = /<(?:TILE_LOCK_PARALLAX|tile lock parallax)>/i
    
  end # MAP
  end # REGEXP
end # YEA

#==============================================================================
# ■ RPG::Map
#==============================================================================

class RPG::Map
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :parallax_lock_x
  attr_accessor :parallax_lock_y
  attr_accessor :parallax_tile_lock
  
  #--------------------------------------------------------------------------
  # common cache: load_notetags_paralock
  #--------------------------------------------------------------------------
  def load_notetags_paralock
    @parallax_lock_x = false
    @parallax_lock_y = false
    @parallax_tile_lock = false
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when YEA::REGEXP::MAP::LOCK_PARALLAX_X
        @parallax_lock_x = true
        @parallax_tile_lock = false
      when YEA::REGEXP::MAP::LOCK_PARALLAX_Y
        @parallax_lock_y = true
        @parallax_tile_lock = false
      when YEA::REGEXP::MAP::FULL_LOCK_PARALLAX
        @parallax_lock_x = true
        @parallax_lock_y = true
        @parallax_tile_lock = false
      when YEA::REGEXP::MAP::TILE_LOCK_PARALLAX
        @parallax_lock_x = false
        @parallax_lock_y = false
        @parallax_tile_lock = true
      #---
      end
    } # self.note.split
    #---
  end
  
end # RPG::Map

#==============================================================================
# ■ Game_Map
#==============================================================================

class Game_Map
  
  #--------------------------------------------------------------------------
  # alias method: setup
  #--------------------------------------------------------------------------
  alias game_map_setup_parallax_paralock setup_parallax
  def setup_parallax
    @map.load_notetags_paralock
    game_map_setup_parallax_paralock
  end
  
  #--------------------------------------------------------------------------
  # new method: parallax_lock_x?
  #--------------------------------------------------------------------------
  def parallax_lock_x?
    return @map.parallax_lock_x
  end
  
  #--------------------------------------------------------------------------
  # new method: parallax_lock_y?
  #--------------------------------------------------------------------------
  def parallax_lock_y?
    return @map.parallax_lock_y
  end
  
  #--------------------------------------------------------------------------
  # new method: parallax_tile_lock?
  #--------------------------------------------------------------------------
  def parallax_tile_lock?
    return @map.parallax_tile_lock
  end
  
  #--------------------------------------------------------------------------
  # alias method: parallax_ox
  #--------------------------------------------------------------------------
  alias game_map_parallax_ox_paralock parallax_ox
  def parallax_ox(bitmap)
    return 0 if parallax_lock_x?
    return @display_x * 32 if parallax_tile_lock?
    return game_map_parallax_ox_paralock(bitmap)
  end
  
  #--------------------------------------------------------------------------
  # alias method: parallax_oy
  #--------------------------------------------------------------------------
  alias game_map_parallax_oy_paralock parallax_oy
  def parallax_oy(bitmap)
    return 0 if parallax_lock_y?
    return @display_y * 32 if parallax_tile_lock?
    return game_map_parallax_oy_paralock(bitmap)
  end
  
end # Game_Map

#==============================================================================
#
# ▼ End of File
#
#==============================================================================


Animated Parallax:
El segundo script se lo debemos a modern algebra y se trata del "Animated Parallax", el cual sirve para poder utilizar una imagen animada como fondo.

Código:
#==============================================================================
#    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

Me despido sin más, esperando que les hayan servido.

Saludos,
Vala.

#2 Re: Parallax Mapping - VXAce el Mar Mar 08, 2016 7:16 pm

Tomate

avatar
¡Muy buenos scripts! ¡Gracias por tu aporte, @Vala!
Ópalo Reputación

Les voy a echar un vistazo. Ópalo Sonriente

#3 Re: Parallax Mapping - VXAce el Miér Mar 09, 2016 2:19 pm

LuRen

avatar
Bien, no uso el VX Ace (todavia...) pero me parece un aporte excelente Ópalo Aplaudiendo.

Ópalo Reputación Sigue así Vala Ópalo Sonrisa Grande
Opalo Hola

Contenido patrocinado


Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje [Página 1 de 1.]

Permisos de este foro:
No puedes responder a temas en este foro.