Picture SlideShow
Version: 1.0
Introduction
This script creates a picture slideshow (or 'coverflow') and let's the user press the Left or Right key on the keyboard to browse to the pictures.
Screenshots
http://img65.imageshack.us/img65/715/slideshow1ij3.jpg[/img]
http://img65.imageshack.us/img65/3434/slideshow2ex0.jpg[/img]
Script
Instructions
1) Paste this script above main
2) call the script with:
$scene = Scene_SlideShow(array_of_pictures)
Default, the images are loaded from the /Panorama folder. If you want to import the images from the /Picture folder, call the script with:
$scene = Scene_SlideShow(array_of_pictures, 'picture')
Example
The images in the example below are in the standard RTP
Compatibility
As far as I know, it only works with RPG MAKER XP.
Credits and Thanks
Thank's to Sephiroth Spawn for the Bitmap.scale_blt method (yep, I know, very old script)
Terms and Conditions
This script is free to use and/or adjust :wink:
Version: 1.0
Introduction
This script creates a picture slideshow (or 'coverflow') and let's the user press the Left or Right key on the keyboard to browse to the pictures.
Screenshots
http://img65.imageshack.us/img65/715/slideshow1ij3.jpg[/img]
http://img65.imageshack.us/img65/3434/slideshow2ex0.jpg[/img]
Script
Code:
#==============================================================================
# ** Picture SlideShow
#------------------------------------------------------------------------------
# Author Freakboy
# Version 1.0
# Date 15/09/08 (DD/MM/YYYY)
#------------------------------------------------------------------------------
# This script creates a picture slideshow (or 'coverflow') and let's the user
# press the Left or Right key on the keyboard to browse to the pictures
#
# Instructions:
# 1) Paste this script above main
# 2) call the script with:
# $scene = Scene_SlideShow(array_of_pictures)
#
# Default, the picture's are loaded from the /Panorama folder. If you want to
# import the images from the /Picture folder, call the script with:
# $scene = Scene_SlideShow(array_of_pictures, 'picture')
#
# Thanks to:
# Sephiroth Spawn for the scale_blt method
#------------------------------------------------------------------------------
# SLIDESHOW SETUP
BITMAP_WIDTH = 200 # Width of the pictures
BITMAP_HEIGHT = 200 # Height of the pictures
BITMAP_X = BITMAP_WIDTH * 0.75 # X-axis spacing between each picture
BITMAP_Y = 10 # Y-axis spacing
SCROLL_LEFT_KEY = Input::LEFT # Define left scrolling key
SCROLL_RIGHT_KEY = Input::RIGHT # Define right scrolling key
# Thank you sephiroth spawn for this method!
class Bitmap
#--------------------------------------------------------------------------
# * Scale Blt
#--------------------------------------------------------------------------
def scale_blt(dest_rect, src_bitmap, src_rect =
Rect.new(0, 0, src_bitmap.width, src_bitmap.height), opacity = 255)
w, h = src_rect.width, src_rect.height
scale = [w / dest_rect.width.to_f, h / dest_rect.height.to_f].max
ow, oh = (w / scale).to_i, (h / scale).to_i
ox, oy = (dest_rect.width - ow) / 2, (dest_rect.height - oh) / 2
stretch_blt(Rect.new(ox + dest_rect.x, oy + dest_rect.y, ow, oh),
src_bitmap, src_rect )
end
end
#==============================================================================
# ** Scene_SlideShow
#------------------------------------------------------------------------------
# This class performs slideshow processing
#==============================================================================
class Scene_SlideShow
#--------------------------------------------------------------------------
# * Initialize
# images : Array of Pictures
#--------------------------------------------------------------------------
def initialize(images, folder='panorama')
# Initialize the images, make sure it's an array
@images = images
@folder = folder
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Setup indexing and scrolling variables
setup_variables()
# Setup the pictures
setup_pictures()
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of content
dispose_pictures()
end
#--------------------------------------------------------------------------
# * Setup Pictures
#--------------------------------------------------------------------------
def setup_pictures()
# Initialize a Viewport
@viewport = Viewport.new(0, 0, 640, 480)
# Create an Array of Sprites
@sprites = [ ]
# Select each image and give a bitmap
for image in @images
s = Sprite.new(@viewport)
# If the folder is 'panorama'
if (@folder == 'panorama')
# Import the image from the /Panorama folder
img = RPG::Cache.panorama(image, 0)
# If the folder is 'picture'
elsif (@folder == 'picture')
# Import the image from the /Picture folder
img = RPG::Cache.picture(image, 0)
else # Otherwise import the image from the /Picture folder
img = RPG::Cache.picture(image, 0)
end
# Define a rect for the bitmap
rect = Rect.new(0, 0, BITMAP_WIDTH, BITMAP_HEIGHT)
s.bitmap = Bitmap.new(BITMAP_WIDTH, BITMAP_HEIGHT)
# Scale the bitmap to the defined Width and Height
s.bitmap.scale_blt(rect, img)
# Put the image in an array
@sprites.push(s)
end
# Update the sprites X, Y and Z location
update_sprites()
end
#--------------------------------------------------------------------------
# * Setup Variables
#--------------------------------------------------------------------------
def setup_variables
# Setup indexing variables
@index = 0.0.to_f
@dest_index = 0.0.to_f
# Setup scrolling variables
@scrolling = false
@scroll_direction = 0
@scroll_frames = 0
end
#--------------------------------------------------------------------------
# * Dispose Pictures
#--------------------------------------------------------------------------
def dispose_pictures()
# Dispose of all sprites
for sprite in @sprites
sprite.dispose
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# If the pictures are scrolling
if (@scrolling)
# If the pictures scroll left
if (@scroll_direction == 4)
# Update Scroll Left
update_scroll_left()
return
end
# If the pictures scroll right
if (@scroll_direction == 6)
# Update Scroll Right
update_scroll_right()
return
end
end
# If you hit the 'x' or the 'esc' button, leave the slideshow and...
if Input.trigger?(Input::B)
# return to the map
$scene = Scene_Map.new
return
end
# If press LEFT and index is smaller then amount of sprites - 1
if (Input.trigger?(SCROLL_LEFT_KEY) && @index < @sprites.size - 1)
# Scroll to left
@scrolling = true
@scroll_direction = 4
@dest_index = @index + 1
return
end
# If press RIGHT and index is greater then 0
if (Input.trigger?(SCROLL_RIGHT_KEY) && @index > 0)
# Scroll to right
@scrolling = true
@scroll_direction = 6
@dest_index = @index - 1
return
end
end
#--------------------------------------------------------------------------
# * Update Sprites
#--------------------------------------------------------------------------
def update_sprites()
# Update the sprites X, Y and Z location
for i in 0...@sprites.size
center_x = 640 / 2 - (BITMAP_WIDTH / 2)
center_y = 480 / 2 - (BITMAP_HEIGHT / 2)
@sprites[i].x = center_x - ((@index.to_f - i) * BITMAP_X)
@sprites[i].y = center_y - ((@index.to_f - i).abs * BITMAP_Y) - 50
@sprites[i].z = 100 - ((@index - i).abs * 20)
end
end
#--------------------------------------------------------------------------
# * Update Scroll Left
#--------------------------------------------------------------------------
def update_scroll_left
# Raise the index slowly
@index += 0.125.to_f
# Update the sprite positions
update_sprites()
# If the index is equal to the dest index
if (@dest_index == @index)
# Stop scrolling
@scrolling = false
return
end
end
#--------------------------------------------------------------------------
# * Update Scroll Right
#--------------------------------------------------------------------------
def update_scroll_right
# Lower the index slowly
@index -= 0.125.to_f
# Update the sprite positions
update_sprites()
# If the index is equal to the dest index
if (@dest_index == @index)
# Stop scrolling
@scrolling = false
return
end
end
end
Instructions
1) Paste this script above main
2) call the script with:
$scene = Scene_SlideShow(array_of_pictures)
Default, the images are loaded from the /Panorama folder. If you want to import the images from the /Picture folder, call the script with:
$scene = Scene_SlideShow(array_of_pictures, 'picture')
Example
The images in the example below are in the standard RTP
Code:
images = ["001-Sky01", "002-Sky02", "003-StarlitSky01", "004-CloudySky01",
"005-Sunset01", "006-Mountains01", "007-Ocean01"
]
$scene = Scene_SlideShow.new(images, 'panorama')
Compatibility
As far as I know, it only works with RPG MAKER XP.
Credits and Thanks
Thank's to Sephiroth Spawn for the Bitmap.scale_blt method (yep, I know, very old script)
Terms and Conditions
This script is free to use and/or adjust :wink: