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