Quick Animations do SephirothSpawn

22 de agosto de 2016

Quick Animations é um script para o RPG Maker XP criado pelo SephirothSpawn que foi desenvolvido para ser como um reprodutor de animações estilo GIF num projeto ou jogo deste maker.

Como imagens neste formato (.GIF) não são reproduzidas no RMXP (sem API), este script ou usa uma série de imagens em um diretório numerado ou em uma imagem com múltiplos frames usadas lado a lado.

Ou seja, o script não reproduz arquivos .GIF, mas emula o seu funcionamento.

Código do Script

#==============================================================================
# ** Quick Animations
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 2
# 2006-08-27
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to act as a GIF animation player. Because GIF
#   images aren't actually able to play in RMXP (without API), this script
#   either uses a series of images in a directory numbered OR an animation
#   like image with multiple frames placed side by side.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#
#   ** Setting Up Animation Type A **
#
#   <your_object> = Quick_Animation_A.new(directory, loop = true, 
#                                         frame_skip = 10, viewport = nil)
#
#     Directory : Folder in Game/Graphics/Pictures in which frames are 
#                 labeled 0 to X
#     Loop : If true, the object will repeat itself until disposed. If false,
#            after the object has played all frames, will self dispose.
#     Frame Skip : The Number of game frames to pass before the next frame is 
#                  displayed.
#     Viewport : Viewport Sprite will be placed on.
#
#   ** Setting Up Animation Type B **
#
#   <your_animation> = Quick_Animation_B.new(bitmap, frames, loop = true, 
#                                            frameskip = 10, viewport = nil)
#
#     Bitmap : Filename of image in Game/Graphics/Pictures Folder.
#     Frames : Number of frames of animation.
#     Loop : If true, the object will repeat itself until disposed. If false,
#            after the object has played all frames, will self dispose.
#     Frame Skip : The Number of game frames to pass before the next frame is 
#                  displayed.
#     Viewport : Viewport Sprite will be placed on.
#
#  ** NOTE: Object must have the update method called to advanced frames.
#     It is advised to update will the unless self.disposed? trailing
#     in the event the object self disposed (loop = false).
#------------------------------------------------------------------------------
# * Credits :
#
#   Thanks Trickster for Animation Type 2 Suggestion
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Quick Animations', 'SephirothSpawn', 2, '2006-08-27')

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state('Quick Animations')
  
#==============================================================================
# ** Quick_Animation_A
#==============================================================================

class Quick_Animation_A < Sprite
  #--------------------------------------------------------------------------
  # * Object Initialization
  #  ~ directory : foldername in Pictures Folder
  #  ~ loop : true or false to loop or not loop image
  #  ~ frame_skip : number of frames to advance next image
  #  ~ viewport : viewport on window
  #--------------------------------------------------------------------------
  def initialize(directory, loop = true, frame_skip = 10, viewport = nil)
    super(viewport)
    # Stores Directory, Loop & Frame Skip Count
    @directory, @loop, @frame_skip = directory, loop, frame_skip
    # Starts Index Count
    @index = 0
    # Updates Bitmap
    update
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Stop Unless Frame Skip Reached
    return unless Graphics.frame_count % @frame_skip == 0
    # Adds 1 to the index
    @index += 1
    # If not Last Image
    if Dir.entries(@directory).include?("#{@index}.png")
      # Sets Bitmap
      self.bitmap = RPG::Cache.load_bitmap(@directory, @index.to_s)
    # If Last Image Already Displayed
    else
      # If Loop Image
      if @loop
        # Reset Index & Update Bitmap
        @index = -1
        update
      # If No Loop
      else
        # Delete Image
        self.dispose
      end
    end
  end
end

#==============================================================================
# ** Quick_Animation_B
#==============================================================================

class Quick_Animation_B < Sprite
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :frames
  #--------------------------------------------------------------------------
  # * Object Initialization
  #  ~ bitmap : filename in Pictures Folder
  #  ~ frames : number of frames
  #  ~ frame_skip : number of frames to advance next image
  #  ~ viewport : viewport on window
  #--------------------------------------------------------------------------
  def initialize(bitmap, frames, loop = true, frameskip = 10, viewport = nil)
    super(viewport)
    # Sets Up Bitmap
    self.bitmap = RPG::Cache.picture(bitmap)
    # Stores Frame, Loop & Frame Skip Count
    @frames, @loop, @frame_skip = frames, loop, frameskip
    # Starts Index Count
    @index = 0
    # Updates Bitmap
    update
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Stop Unless Frame Skip Reached
    return unless Graphics.frame_count % @frame_skip == 0
    # Adds 1 to the index
    @index += 1
    # If Passed Last Frame
    if @index == @frames
      # If Loop Image
      if @loop
        # Reset Index & Update Bitmap
        @index = -1
        update
      # If No Loop
      else
        # Delete Image
        self.dispose
      end
    end
    # Updates Src Rect
    x = (w = self.bitmap.width / @frames) * @index
    self.src_rect.set(x, 0, w, self.bitmap.height)
  end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Clique aqui e saiba como. Obrigado!

Deixe um comentário

Inscreva-se na nossa newsletter!