Scrollable Text
#1
Scrollable Text
Version: 1.0


Introduction
This script is useful for windows that just displays information and doesn't select anything. You can set the speed the windows/sprite contents scroll. This is just two classes Window_Scrollable and Sprite Scrollable.


Screenshots
One looks like plain window and the other looks like some text on the screen.


Script
Window Scrollable
Code:
#==============================================================================
# ** Window_Scrollable
#------------------------------------------------------------------------------
#  This window class contains scroll functions.
#==============================================================================

class Window_Scrollable < Window_Base
  attr_accessor :speed
  attr_accessor :contents_rect
  attr_writer   :horizantal_scroll
  attr_writer   :vertical_scroll
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x      : window x-coordinate
  #     y      : window y-coordinate
  #     width  : window width
  #     height : window height
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @contents_rect = Rect.new(0,0,width,height)
    @speed = 0
    @horizantal_scroll = false
    @vertical_scroll = false
  end
  #--------------------------------------------------------------------------
  # * Can be moved vertically?
  #--------------------------------------------------------------------------
  def vertical?
    return false if self.contents == nil
    return self.contents.height > self.height - 32
  end
  #--------------------------------------------------------------------------
  # * Can be moved horizantally?
  #--------------------------------------------------------------------------
  def horizantal?
    return false if self.contents == nil
    return self.contents.width > self.width - 32
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    return if not self.active
    if Input.repeat?(Input::UP)
      if self.oy > @contents_rect.y and @vertical_scroll and vertical?
        self.oy = [self.oy - speed, @contents_rect.y].max
      end
    end
    if Input.repeat?(Input::LEFT)
      if self.ox > @contents_rect.x and @horizantal_scroll and horizantal?
        self.ox = [self.ox - speed, @contents_rect.x].max
      end
    end
    if Input.repeat?(Input::DOWN)
      if self.oy < @contents_rect.height - (self.height - 32) and @vertical_scroll and vertical?
        self.oy = [self.oy + speed, @contents_rect.height].min
      end
    end
    if Input.repeat?(Input::RIGHT)
      if self.ox < @contents_rect.width - (self.width - 32)  and @horizantal_scroll and horizantal?
        self.ox = [self.ox - speed, @contents_rect.width].min
      end
    end
  end
end

SpriteScrollable
Code:
class Scroll_Sprite < Sprite

  def initialize(x,y,width,height, viewport = nil)
    super(viewport)
    self.x = x
    self.y = y
    self.width = width
    self.height = height
  end
  
  def sx=(ox)
    self.src_rect.x = ox
  end
  
  def sy=(oy)
    self.src_rect.y = oy
  end
  
  def sx
    return self.src_rect.x
  end
  
  def sy
    return self.src_rect.y
  end
  
  def width
    return self.src_rect.width
  end
  
  def height
    return self.src_rect.height
  end
  
  def width=(width)
    self.src_rect.width = width
    @width = width
  end
  
  def height=(height)
    self.src_rect.height = height
    @height = height
  end
  
  def bitmap=(bitmap)
    super(bitmap)
    self.src_rect.width = @width
    self.src_rect.height = @height
  end
end

#==============================================================================
# ** Srite_Selectable
#------------------------------------------------------------------------------
#  This sprite class contains scroll functions.
#==============================================================================

class Sprite_Scrollable < Scroll_Sprite
  attr_accessor :speed
  attr_accessor :bitmap_rect
  attr_writer   :horizantal_scroll
  attr_writer   :vertical_scroll
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x      : window x-coordinate
  #     y      : window y-coordinate
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x,y,width,height)
    @bitmap_rect = Rect.new(0,0,width,height)
    @speed = 0
    @horizantal_scroll = false
    @vertical_scroll = false
  end
  #--------------------------------------------------------------------------
  # * Get Normal Text Color
  #--------------------------------------------------------------------------
  def normal_color
    return Color.new(255, 255, 255, 255)
  end
  #--------------------------------------------------------------------------
  # * Get Disabled Text Color
  #--------------------------------------------------------------------------
  def disabled_color
    return Color.new(255, 255, 255, 128)
  end
  #--------------------------------------------------------------------------
  # * Get System Text Color
  #--------------------------------------------------------------------------
  def system_color
    return Color.new(192, 224, 255, 255)
  end
  
  def vertical?
    return false if self.bitmap == nil
    return self.bitmap.height > self.height
  end
      
  def horizantal?
    return false if self.bitmap == nil
    return self.bitmap.width > self.width
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    if Input.repeat?(Input::UP)
      if self.sy > @bitmap_rect.y and @vertical_scroll and vertical?
        self.sy = [self.sy - speed, @bitmap_rect.y].max
      end
    end
    if Input.repeat?(Input::LEFT)
      if self.sx > @bitmap_rect.x and @horizantal_scroll and horizantal?
        self.sx = [self.sx - speed, @bitmap_rect.x].max
      end
    end
    if Input.repeat?(Input::DOWN)
      if self.sy < @bitmap_rect.height - self.height and @vertical_scroll and vertical?
        self.sy = [self.sy + speed, @bitmap_rect.height].min
      end
    end
    if Input.repeat?(Input::RIGHT)
      if self.sx < @bitmap_rect.width - self.width and @horizantal_scroll and horizantal?
        self.sx = [self.sx - speed, @bitmap_rect.width].min
      end
    end
  end
end


Instructions

First you window must inherit from the class you wish to use

Window_Scrollable
for the window to be scrollable you must set the speed, which way the window is able to scroll, and the contents_rect

so in the initialize method or whatever

self.speed = speed
self.horizantal_scroll = boolean
self.vertical_scroll = boolean
self.contents_rect.set(0,0,width-32,height-32)

Sprite_Scrollable
This class is used for scrolling text, also used in my mission system for windows that have a header and adding a secondary window make everything look weird, this class was used to imitiate the contents of the window.

you set it up the same way,except contents_rect is replaced by bitmap_rect and to draw to the bitmap you use self.bitmap.draw_text, also included within the class is the normal color system color and disabled color


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
Compatible with anything and everything


Author's Notes
Do not post I am confused what does this do or else as I stated this is a tool for scripters and not an actual script you plug into your project. If you need further instruction just ask.

Can be used for more advanced things.


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 }


Messages In This Thread
Scrollable Text - by Trickster - 03-02-2008, 06:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Text Scroll Script - Enhanced DerVVulfman 23 34,319 02-18-2021, 04:16 AM
Last Post: DerVVulfman
   Message Text from Files DerVVulfman 0 5,286 04-13-2016, 03:25 AM
Last Post: DerVVulfman
   Text Extraction Generator DerVVulfman 5 12,954 10-13-2014, 09:32 PM
Last Post: Narzew
   Text to RGSS DerVVulfman 10 25,627 05-04-2013, 04:34 AM
Last Post: DerVVulfman
   Damage Text Revamp 2.1 PK8 3 12,832 04-08-2012, 06:47 PM
Last Post: PK8
   Auto-Sizing Text Windows RPG Advocate 9 18,939 06-11-2011, 06:18 PM
Last Post: sagam12
   Another Scrolling Text Script kyonides 1 6,478 04-12-2010, 01:36 AM
Last Post: Shiroiyuki
   Damage Text Edit ParaDog 0 5,074 03-05-2008, 08:22 AM
Last Post: ParaDog
   Command Windows - Animated Text Selwyn 0 4,326 03-03-2008, 06:18 AM
Last Post: Selwyn
   One-Letter-at-a-Time Text Display Script Anonymous 0 5,032 03-03-2008, 05:41 AM
Last Post: Anonymous



Users browsing this thread: 1 Guest(s)