Window Sprites
#1
Window Sprites
Version: 2.0.1


Introduction
This simple script lets you tag sprites to a window, when they are tagged it automatically updates/disposes/moves with the window.


Screenshots
Take a sprite and add it to a window. There is your screenshot right there.


Demo
For a demo of this script in action see the following

Animated Gradient Bars
Skill Shop
State Cycling


Script
Ok, ok I'll spare the families this time.

Code:
#============================================================================
# ** Window Sprites
#----------------------------------------------------------------------------
# Trickster
# Version 2.0.1
# Date 3/5/07
# SDK Version : 2.1
#============================================================================

#--------------------------------------------------------------------------
# * Begin SDK Log
#--------------------------------------------------------------------------
SDK.log("Window Sprites", "Trickster", 2.01, "3.24.07")

#--------------------------------------------------------------------------
# * Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1])

#--------------------------------------------------------------------------
# * Begin SDK Enable Test
#--------------------------------------------------------------------------
if SDK.enabled?("Window Sprites")
  
class Window_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  if @trick_sprites_windowbase.nil?
    alias_method :trick_sprites_base_x=, :x=
    alias_method :trick_sprites_base_y=, :y=
    alias_method :trick_sprites_base_z=, :z=
    alias_method :trick_sprites_base_ox=, :ox=
    alias_method :trick_sprites_base_oy=, :oy=
    alias_method :trick_sprites_base_width=, :width=
    alias_method :trick_sprites_base_height=, :height=
    alias_method :trick_sprites_base_contents_opacity=, :contents_opacity=
    alias_method :trick_sprites_base_back_opacity=, :back_opacity=
    alias_method :trick_sprites_base_opacity=, :opacity=
    alias_method :trick_sprites_base_visible=, :visible=
    @trick_sprites_windowbase = true
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias_method :trick_sprites_base_initialize, :initialize
  def initialize(x, y, width, height)
    # Setup Sprites Array
    @window_sprites = []
    # The Usual
    trick_sprites_base_initialize(x, y, width, height)
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  alias_method :trick_sprites_base_dispose, :dispose
  def dispose
    # The Usual
    trick_sprites_base_dispose
    # Dispose all Sprites
    @window_sprites.each {|sprite| sprite.dispose}
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  alias_method :trick_sprites_base_update, :update
  def update
    # The Usual
    trick_sprites_base_update
    # Update
    @window_sprites.each {|sprite| sprite.update}
  end
  #--------------------------------------------------------------------------
  # * Set X
  #--------------------------------------------------------------------------  
  def x=(x)
    # Run through each window sprite
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch by Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover', 'background', 'background2'
          # Include Scroll Calculation Set X
          sprite.x = sprite.x - self.x + x + ox
        when 'border'
          # Exclude Scroll Calculation Set X
          sprite.x = sprite.x - self.x + x
        end
      else
        # Default is Content Sprite
        sprite.x = sprite.x - self.x + x + ox
      end
    end
    # The Usual
    self.trick_sprites_base_x = x
  end
  #--------------------------------------------------------------------------
  # * Set Y
  #--------------------------------------------------------------------------
  def y=(y)
    # Update All Y's
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch by Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover', 'background', 'background2'
          # Include Scroll Calculation Set Y
          sprite.y = sprite.y - self.y + y + oy
        when 'border'
          # Exclude Scroll Calculation Set Y
          sprite.y = sprite.y - self.y + y
        end
      else
        # Default is Content Sprite
        sprite.y = sprite.y - self.y + y + oy
      end
    end
    # The Usual
    self.trick_sprites_base_y = y
  end
  #--------------------------------------------------------------------------
  # * Set Z
  #--------------------------------------------------------------------------
  def z=(z)
    # Update All Z's
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch By Sprite Type
        case sprite.sprite_type
        when 'content'
          sprite.z = self.z + 1
        when 'content2'
          sprite.z = self.z + 2
        when 'cover', 'border'
          sprite.z = self.z + 3
        when 'background'
          sprite.z = self.z
        when 'background2'
          sprite.z = self.z - 1
        end
      else
        # Default is content
        sprite.z = self.z + 1
      end
    end
    # The Usual
    self.trick_sprites_base_z = z
  end
  #--------------------------------------------------------------------------
  # * Set Origin X
  #--------------------------------------------------------------------------
  def ox=(ox)
    # Get Ox Change
    cx = self.ox - ox
    # Run Through Each Sprite
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch By Sprite Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover', 'background', 'background2'
          # Add to X
          sprite.x += cx
          # Setup Visibility
          sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
        end
      else
        # Add to X
        sprite.x += cx
        # Setup Visibility
        sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
      end
    end
    # The Usual
    self.trick_sprites_base_ox = ox
  end
  #--------------------------------------------------------------------------
  # * Set Origin Y
  #--------------------------------------------------------------------------
  def oy=(oy)
    # Get Oy Change
    cy = self.oy - oy
    # Run Through Each Sprite
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch By Sprite Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover', 'background', 'background2'
          # Add to Y
          sprite.y += cy
          # Setup Visibility
          sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
        end
      else
        # Add to Y
        sprite.y += cy
        # Setup Visibility
        sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
      end
    end
    # The Usual
    self.trick_sprites_base_oy = oy
  end
  #--------------------------------------------------------------------------
  # * Set Width
  #--------------------------------------------------------------------------
  def width=(width)
    # Run Through Each Sprite
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch By Sprite Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover', 'background', 'background2'
          # Setup Visibility
          sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
        end
      else
        # Setup Visibility
        sprite.visible = sprite.x.between?(x + 16, x + width - 16) && visible
      end
    end
    # The Usual
    self.trick_sprites_base_width = width
  end
  #--------------------------------------------------------------------------
  # * Set Height
  #--------------------------------------------------------------------------
  def height=(height)
    # Run Through Each Sprite
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch By Sprite Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover', 'background', 'background2'
          # Setup Visibility
          sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
        end
      else
        # Setup Visibility
        sprite.visible = sprite.y.between?(y + 16, y + height - 16) && visible
      end
    end
    # The Usual
    self.trick_sprites_base_height = height
  end
  #--------------------------------------------------------------------------
  # * Set Contents Opacity
  #--------------------------------------------------------------------------
  def contents_opacity=(opacity)
    # Run Through Each Sprite and Setup Opacity
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch By Sprite Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover'
          # Setup Opacity
          sprite.opacity = opacity
        end
      else
        # Setup Opacity
        sprite.opacity = opacity
      end
    end
    # The Usual
    self.trick_sprites_base_contents_opacity = opacity
  end
  #--------------------------------------------------------------------------
  # * Set Back Opacity
  #--------------------------------------------------------------------------
  def back_opacity=(opacity)
    # Run Through Each Sprite and Setup Opacity
    @window_sprites.each do |sprite|
      # Skip if not Has Method sprite type
      next if not sprite.respond_to?(:sprite_type)
      # Branch By Sprite Type
      case sprite.sprite_type
      when 'background', 'background2'
        # Setup Opacity
        sprite.opacity = opacity
      end
    end
    # The Usual
    self.trick_sprites_base_back_opacity = opacity
  end
  #--------------------------------------------------------------------------
  # * Set Opacity
  #--------------------------------------------------------------------------
  def opacity=(opacity)
    # Run Through Each Sprite and Setup Opacity
    @window_sprites.each do |sprite|
      # Skip if not Has Method sprite type
      next if not sprite.respond_to?(:sprite_type)
      # Branch By Sprite Type
      case sprite.sprite_type
      when 'border', 'tagged'
        # Setup Opacity
        sprite.opacity = opacity
      end
    end
    # The Usual
    self.trick_sprites_base_opacity = opacity
  end
  #--------------------------------------------------------------------------
  # * Set Visibility
  #--------------------------------------------------------------------------
  def visible=(bool)
    # Get Rect
    rect = Rect.new(x + 16, y + 16, width - 32, height - 32)
    # Run Through Each Sprite
    @window_sprites.each do |sprite|
      # If Has Method sprite type
      if sprite.respond_to?(:sprite_type)
        # Branch By Sprite Type
        case sprite.sprite_type
        when 'content', 'content2', 'cover', 'background', 'background2'
          sprite.visible = bool && sprite.in_rect?(rect)
        when 'border', 'tagged'
          sprite.visible = visible
        end
      else
        sprite.visible = bool && sprite.in_rect?(rect)
      end
    end
    # Update Visibility
    self.trick_sprites_base_visible = bool
  end
end

class Sprite
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :sprite_type
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  if @trick_sprites_sprite.nil?
    alias_method :trick_sprites_sprite_initialize, :initialize
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(*args)
    # The Usual
    trick_sprites_sprite_initialize(*args)
    # Setup Default for sprite_type - 'content'
    @sprite_type = 'content'
  end
  #--------------------------------------------------------------------------
  # * Tag
  #--------------------------------------------------------------------------
  def tag(window)
    # Get Attributes
    x, y, width, height = window.x, window.y, window.width, window.height
    # Setup Rect
    rect = Rect.new(x + 16, y + 16, width - 32, height - 32)
    # Branch by Sprite Type
    case sprite_type
    when 'content'
      # Set Visibility
      self.visible = in_rect?(rect) && window.visible
      # Set Z Between Window
      self.z = window.z + 1
      # Setup Opacity
      self.opacity = window.contents_opacity
    when 'content2'
      # Set Visibility
      self.visible = in_rect?(rect) && window.visible
      # Set Z Between Window
      self.z = window.z + 2
      # Setup Opacity
      self.opacity = window.contents_opacity
    when 'cover'
      # Set Visibility
      self.visible = in_rect?(rect) && window.visible
      # Set Z Between Window
      self.z = window.z + 3
      # Setup Opacity
      self.opacity = window.contents_opacity
    when 'border'
      # Set Visibility
      self.visible = window.visible
      # Set Z Between Window
      self.z = window.z + 3
      # Setup Opacity
      self.opacity = window.opacity
    when 'background'
      # Set Visibility
      self.visible = in_rect?(rect) && window.visible
      # Set Z at Window
      self.z = window.z
      # Setup Opacity
      self.opacity = window.back_opacity
    when 'background2'
      # Set Visibility
      self.visible = in_rect?(rect) && window.visible
      # Set Z at Window
      self.z = window.z - 1
      # Setup Opacity
      self.opacity = window.back_opacity
    when 'tagged'
      # Set Visibility
      self.visible = window.visible
      # Setup Opacity
      self.opacity = window.opacity
    end
  end
  #--------------------------------------------------------------------------
  # * In Rect?
  #--------------------------------------------------------------------------
  def in_rect?(*rect)
    # If 1 Argument Sent
    if rect.size == 1
      # Get Rect
      rect = rect[0]
      # Return in rect state
      return (x.between?(rect.x, rect.x + rect.width) &&
      y.between?(rect.y, rect.y + rect.height))
    else
      # Get variables sent
      x, y, width, height = rect
      # If In Rect
      return self.x.between?(x, x + width) && self.y.between?(y, y + height)
    end
  end
end
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end


Instructions
Add Above Main

Then in any window class (By this I mean any child of Window_Base) just do this:

Code:
@window_sprites <<
.tag(

where is a Sprite object

and window is the window you want to tag the sprite to

NEW types have been added

to change the type of tagging used on a sprite just call
.sprite_type = type

where type is either content, content2, cover, border, background, background2 tagged

content and contents2 are the same except contents2 is positioned higher than content
content.z = window.z + 1 contents2.z = window.z + 2

cover is like contents but is positioned over the window
cover.z = window.z + 3

border is like cover but it can be positioned outside the contents of the window

background is like contents but is positioned below the window
background2 is like background but it is positioned below background
background.z = window.z, background2.z = window.z - 1

tagged is just a tagged sprite to a window you are free to position it anywhere

Also the default for all sprites is content

Note you can also add other objects to the window sprite array, but the object you push must respond to methods x=, y=, z=, visible=, opacity=
if you define a method called sprite_type within the object's class you can set the type of tagging used, but if you don't define it the script will use content tagging.


FAQ
Note: Permission granted by Trickster to post:
Quote:And if you post what you have now of my stuff then you don't have the latest versions. I'm too lazy/busy to post stuff.
As this is his material, it is deletable upon his request. Due to his current absense, no support is available. Please do not PM or eMail him for support.


Compatibility
Should be compatible with any other script

Requires SDK Part 1


Author's Notes
Please do not post saying you don't know what this does, if you can't figure it out then chances are you won't have a use for this. If you do post you will be getting a surprise from me (and it will not be a good surprise)


Terms and Conditions
Hey, I posted this publicly. You can use it. What do you expect? But if you do use it, I do expect you to spell my name correctly in your game. And yes you can use it in commercial games too.
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Toggle Message Window XP kyonides 0 77 11-11-2024, 01:28 AM
Last Post: kyonides
   Tiny Overworld Sprites XP ccoa 5 11,751 08-03-2014, 03:47 AM
Last Post: firestalker
   Battle Report Script Window style mageone 4 16,810 03-20-2013, 10:51 PM
Last Post: KasperKalamity
   Mr.Mo ABS Game Log Window JayRay 0 5,370 10-30-2012, 06:54 AM
Last Post: JayRay
   Semi Ace Window System XP kyonides 0 5,664 10-01-2012, 11:25 PM
Last Post: kyonides
   Naramura Window System Kirito 2 11,042 05-06-2012, 05:40 AM
Last Post: Kirito
   Advanced Shop Status Window RPG Advocate 4 12,484 08-21-2011, 05:12 AM
Last Post: DerVVulfman
   Punky's RealTime Window DerVVulfman 1 5,739 03-22-2010, 08:52 AM
Last Post: MFBMR
   Picture Message Window - With Ease Mac 0 4,893 03-08-2008, 01:02 AM
Last Post: Mac
   Status DBS Window (2 Minute Script) Mac 0 5,054 03-07-2008, 06:44 PM
Last Post: Mac



Users browsing this thread: 1 Guest(s)