Main Menu
  • Welcome to The RPG Maker Resource Kit.

Sliding Graphics

Started by modern algebra, July 01, 2011, 04:37:05 PM

0 Members and 1 Guest are viewing this topic.

modern algebra

Sliding Graphics
Version: 1.0
Author: modern algebra
Date: Canada Day, 2011 (July 1)

Version History




  • <Version 1.0> 2011.07.01 - Original Release

Description



This is a scripter's tool that allows you to slide any graphics in the scene of your choice. It is a very simple function which any scripter could do on their own, of course, but this should make it slightly easier.

Features


  • This script gives an easy way to smoothly slide graphics on the screen
  • Can slide any window or sprite and easily check when they're sliding

Instructions

This is a tool for scripters. It will do nothing on its own. That said, if you are a scripter, then please see the header of the script for instructions. You can also take a look at the sample scripts to see how it is used.

Script




#==============================================================================
#    Sliding Graphics
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: Canada Day, 2011 (July 1)
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This is a scripter's tool that allows you to slide any graphics in the
#   scene of your choice. It is a very simple function which any scripter could
#   do on their own, of course, but this should make it slightly easier.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    This script adds the following method to Scene_Base:
#
#      start_slide (dest_x, dest_y, object, frames, start_se, finish_se)
#        dest_x    : the x coordinate you want the object to end up at
#        dest_y    : the y coordinate you want the object to end up at
#        object    : the graphic (window or sprite) you want to move
#        frames    : the number of frames it takes to get there. If left empty,
#                   defaults to 30 frames (half a second)
#        start_se  : a string holding the name of the SE to play when starting
#                   the slide. You can also make it an array and add volume and
#                   pitch. If the SE file does not exist, it won't cause an
#                   error - it just won't play it.
#        finish_se : a string holding the name of the SE to play when ending
#                   the slide. You can also make it an array and add volume and
#                   pitch. If the SE file does not exist, it won't cause an
#                   error - it just won't play it.
#
#      If you are calling it from somewhere else (not in the scene), you just
#     use:
#       $scene.start_slide (dest_x, dest_y, object, frames, start_se, finish_se)
#
#    EXAMPLE:
#      Say you are in the default menu scene and you want to slide the gold
#     window up to right below the command window in 1/3 of a second, you would
#     do the following:
#
#        start_slide (0, @command_window.height, @gold_window, 20)
#
#      If you wanted also to play the "Open1" SE when starting the slide and
#     the "Close1" SE (at 100 volume but 80 pitch) when finishing, it would be:
#
#        start_slide (0, @command_window.height, @gold_window, 20, "Open1", ["Close1", 100, 80])
#
#    Also, at line 62, you will see the MASG_INACTIVE_WHEN_SLIDING option. If
#   you turn this to true, you can make it so that the player can't use the
#   selectable windows. Otherwise, it won't affect that operation at all.
#
#    Finally, if you want to check whether a particular object is sliding at
#   any given time, there is another method in Scene_Base for that:
#
#      sliding? (object)
#        object : the graphic (window or sprite) you want to check is sliding.
#          If you exclude this argument, then the method will just check if
#          anything is sliding.
#==============================================================================
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#  EDITABLE REGION
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  Turn this option to false if you want to be able to operate selectable
# windows even if they are sliding.
MASG_INACTIVE_WHEN_SLIDING = true
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  END EDITABLE REGION
#//////////////////////////////////////////////////////////////////////////////

$imported = {} unless $imported
$imported["MASlidingGraphics"] = true

#==============================================================================
# ** Window_Selectable
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - active
#==============================================================================

class Window_Selectable
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Active
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mlgb_slidwin_actv_3ts8 active unless self.method_defined? (:mlgb_slidwin_actv_3ts8)
  def active (*args, &block)
    return false if MASG_INACTIVE_WHEN_SLIDING && $scene && $scene.class.method_defined? (:sliding?) && $scene.sliding? (self)
    return mlgb_slidwin_actv_3ts8 (*args, &block) # Run Original Method
  end
end

#==============================================================================
# ** Scene_Base
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - initialize; update
#    new_method - start_slide; sliding?
#==============================================================================

class Scene_Base
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_objslide_strt_5rf1 start
  def start (*args, &block)
    @ma_sliding_objects = []
    ma_objslide_strt_5rf1 (*args, &block) # Run Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Frame Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mlg_slidinobjt_updt_4ev5 update
  def update (*args, &block)
    # Slide the objects
    for slider in @ma_sliding_objects
      slider[1] += slider[2]       # Add to X
      slider[3] += slider[4]       # Add to Y
      slider[5] -= 1               # Subtract from frames
      slider[0].x = slider[1].to_i # Set X to match float
      slider[0].y = slider[3].to_i # Set Y to match float
      if slider[5] <= 0 # Remove when done
        masg_play_se (slider[6])
        @ma_sliding_objects.delete (slider)
      end
    end
    mlg_slidinobjt_updt_4ev5 (*args, &block) # Run Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Start Slide
  #    object         : the Window or Sprite to move
  #    dest_x; dest_y : the x and y position the object should end at
  #    frames         : number of frames it takes to get to its destination
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def start_slide (dest_x, dest_y, object, frames = 30, start_se = [], fin_se = [])
    return if !(object.class.method_defined? (:x) && object.class.method_defined? (:y))
    # If the object is already sliding, replace it
    @ma_sliding_objects.reject! { |sliding_object| sliding_object[0] == object }
    speed_x = (dest_x - object.x).to_f / frames
    speed_y = (dest_y - object.y).to_f / frames
    masg_play_se (start_se)
    @ma_sliding_objects.push ([object, object.x.to_f, speed_x, object.y.to_f, speed_y, frames, fin_se])
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Sliding?
  #    object : the object to see if it is sliding
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def sliding? (object = nil)
    return @ma_sliding_objects && (object.nil? ? !@ma_sliding_objects.empty? : @ma_sliding_objects.assoc (object) != nil)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * MASG Play SE
  #    se : se to play
  #``````````````````````````````````````````````````````````````````````````
  #  This method checks if the SE exists and converts it, then plays it)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def masg_play_se (se = [])
    return if se.empty?
    se = [se] if se.is_a? (String)
    begin
      (RPG::SE.new (*se)).play
    rescue
    end
  end
end


For a sample on how to implement this script, see Chigoo's Sliding Default Menu System.

Credit




  • modern algebra

Thanks


Support



Please post here at RMRK for support.

Known Compatibility Issues

It should work with almost anything as long as you put it below any other custom scripts you might have.

Demo



To see a sample of how this script can be implemented into a scene, take a look at the demo, featuring Chigoo's Sliding Default Menu System

Author's Notes



My choice to modify Scene_Base rather than Window_Base and Sprite_Base is a little odd, but I did it for two reasons: first, I wanted it to apply to any objects with x and y values for compatibility reasons, since I know there have been efforts before to rewrite the window and sprite classes; second, I was lazy and didn't want to repeat the same things in both Sprite_Base and Window_Base.

exhydra

Nice! Your code always looks so pretty. Oh, and useful too!

UPDATED 05-29-14


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

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

Bravo2Kilo

when used in the same project as OriginalWij's Chest Item Popup
i get this error
QuoteScript 'Sliding Windows' line 114: NoMethodError occured
undefined method 'each' for nil:NilClass
I have a blog now where I will be posting my scripts that I create.

My Favorite Animes:
    1. Full Metal Panic (all 3 seasons)
    2. Dragonaut the Resonance
    3. The Legend of the Legendary Heroes
    4. Spice and Wolf
    5. Rosario + Vampire

modern algebra

And you made sure it is under OriginalWij's Chest Popup in the script order?

Bravo2Kilo

i have tried it with OriginalWij's Chest Popup first and sliding graphics last; and i tried it with sliding graphics first and OriginalWij's Chest Popup last
when i commented out the sliding graphics script i didn't get the error

i should have said this in my last post but the error on happens when you get an item from an event, that is when the chest item popup happens
I have a blog now where I will be posting my scripts that I create.

My Favorite Animes:
    1. Full Metal Panic (all 3 seasons)
    2. Dragonaut the Resonance
    3. The Legend of the Legendary Heroes
    4. Spice and Wolf
    5. Rosario + Vampire

Infinate X

Maybe since the icon slides, or since the window isn't set to kniw if it slides or not

This is awesome :D