O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

Pictures Slideshow

Iniciado por LoboShow, 30/03/2013 às 12:08

Pictures Slideshow

Compativel com: RMXP
Compatibilidade: ?
Facilidade de uso: ?
Lag gerado: ?

[box class=titlebg]
Para que serve o script
[/box]
Este script cria uma imagem slideshow e deixa o usuário pressionar a tecla esquerda ou direita do teclado para navegar para as fotos.

[box class=titlebg]
Imagens
[/box]
Spoiler

[close]

[box class=titlebg]
Script
[/box]
#==============================================================================
# ** 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


[box class=titlebg]
Créditos e Avisos
[/box]
Criador: Freakboy
SephirothSpawn pelo método Bitmap.scale_blt