Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved]Quick Animations in Window

Sorry for the noobish question, but how i use the "Quick Animations" of MACL 2.2.
Actually I wanted to learn how to put an animated image in a window, example:

http://i433.photobucket.com/albums/qq55 ... ns/ss1.png[/img]

Below follows the script "Quick Animations":

#==============================================================================
# ** Systems.Quick Animations (3.01)                          By SephirothSpawn
#------------------------------------------------------------------------------
# * 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 :
#
#   * Creating Animated Sprite
#
#     object = Sprite_Animation.new({<parameters>})
#
#   * Creating Animated Plane
#
#     object = Plane_Animation.new({<parameters>})
#
#   * Parameters
#
#     'type'   => 'A' or 'B'
#       - Type of Animation (A : Directory of images, B : Spriteset)
#     'loop'   => true or false
#       - loop (true : loops, false : plays then disposes)
#     'fs'     => n
#       - frameskip (number of frames to go to next frame)
#     'vp'     => Viewport
#       - viewport (sprite viewport)
#
#     Required For Type A
#     'dir'    => 'Graphics/...'
#       - directory of images
#
#     Required For Type B
#     'frames' => n
#       - number of frames on spriteset
#     'bitmap' => 'filename'
#       - filename in pictures folder
#------------------------------------------------------------------------------
# * Credits :
#
#   Thanks Trickster for Animation Type 2 Suggestion
#==============================================================================

#==============================================================================
# ** Sprite_Animation
#==============================================================================
 
class Sprite_Animation < Sprite
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(parameters = {})
    # Assigns Defaults (If Non-Defined)
    @type = parameters.has_key?('type')     ? parameters['type']   : 'A'
    @loop = parameters.has_key?('loop')     ? parameters['loop']   : true
    @frameskip = parameters.has_key?('fs')  ? parameters['fs']     : 10
    @dir = parameters.has_key?('dir')       ? parameters['dir']    : nil
    @frames = parameters.has_key?('frames') ? parameters['frames'] : 1
    viewport = parameters.has_key?('vp')    ? parameters['vp']     : nil
    bitmap = parameters.has_key?('bitmap')  ? parameters['bitmap'] : ''
    # Creates Viewport
    super(viewport)
    # Sets Index
    @index = -1
    # Sets Specialized Parameters
    if @type.upcase == 'B'
      # Sets Frame Number & Sets Bitmap
      self.bitmap = Cache.picture(bitmap)
    end
    # Update
    update
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Stop Unless Proceed Frame
    return unless Graphics.frame_count % @frameskip == 0
    # Increase Index
    @index += 1
    # Branch By Type
    if @type.upcase == 'A'
      # Update Type A
      update_type_a
    elsif @type.upcase == 'B'
      # Update Type B
      update_type_b
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Type A
  #--------------------------------------------------------------------------
  def update_type_a
    # Begin
    begin
      # Load Bitmap
      self.bitmap = Cache.load_bitmap(@dir, @index.to_s)
    # If Bitmap Cannot Be Found
    rescue
      # If Looping
      if @loop
        # Reset Index
        @index = - 1
        update
      else
        # Dispose Image
        self.dispose
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Type B
  #--------------------------------------------------------------------------
  def update_type_b
    # 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
        return
      end
    end
    # Updates Src Rect
    x = (w = self.bitmap.width / @frames) * @index
    self.src_rect.set(x, 0, w, self.bitmap.height)
  end
end

#==============================================================================
# ** Plane_Animation
#==============================================================================
 
class Plane_Animation < Plane
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(parameters = {})
    # Assigns Defaults (If Non-Defined)
    @type = parameters.has_key?('type')     ? parameters['type']   : 'A'
    @loop = parameters.has_key?('loop')     ? parameters['loop']   : true
    @frameskip = parameters.has_key?('fs')  ? parameters['fs']     : 10
    @dir = parameters.has_key?('dir')       ? parameters['dir']    : nil
    @frames = parameters.has_key?('frames') ? parameters['frames'] : 1
    viewport = parameters.has_key?('vp')    ? parameters['vp']     : nil
    bitmap = parameters.has_key?('bitmap')  ? parameters['bitmap'] : ''
    # Creates Viewport
    super(viewport)
    # Sets Index
    @index = -1
    # Sets Specialized Parameters
    if @type.upcase == 'B'
      # Sets Frame Number & Sets Bitmap
      @_bitmap = Cache.picture(bitmap)
    end
    # Update
    update
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Stop Unless Proceed Frame
    return unless Graphics.frame_count % @frameskip == 0
    # Increase Index
    @index += 1
    # Branch By Type
    if @type.upcase == 'A'
      # Update Type A
      update_type_a
    elsif @type.upcase == 'B'
      # Update Type B
      update_type_b
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Type A
  #--------------------------------------------------------------------------
  def update_type_a
    # Begin
    begin
      # Load Bitmap
      self.bitmap = Cache.load_bitmap(@dir, @index.to_s)
    # If Bitmap Cannot Be Found
    rescue
      # If Looping
      if @loop
        # Reset Index
        @index = - 1
        update
      else
        # Dispose Image
        self.dispose
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Type B
  #--------------------------------------------------------------------------
  def update_type_b
    # 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
        return
      end
    end
    # Updates Bitmap
    b = Bitmap.new((w = @_bitmap.width) / @frames, (h = @_bitmap.height))
    b.blt(0, 0, @_bitmap, Rect.new(w / @frames * @index, 0, b.width, h))
    self.bitmap = b
  end
end

Below follows the code of the window "Display":

#######################################################################
class Window_Display < Window_Base

  def initialize(x, y)
    super (x, y, 544, 150)   
    refresh
  end

  def refresh
    self.contents.clear
    draw_face("Actor1", 0, 0, 0, size = 96)
    self.contents.draw_text(97, 0, 100, WLH, "Aqui segue uma demo")
    self.contents.draw_text(97, 0, 100, WLH + 36, "de como fazer ")
  end

 
end
#######################################################################

Now I would like to know where and how should I put the code to display the image animated.

The script has instructions on how you use, but I can not understand.

My attempt failed: :dead:

#######################################################################
self.contents.clear
    @viewport = Viewport.new(0, 0, 544, 416)
    bitmap = Sprite_Animation.new('type' = {'A'}, 'loop' = {true}, 'fs' = {0}, 'dir' = {'Graphics/teste'},'vp' = {@viewport})
    cw = bitmap.width
    ch = bitmap.height
    # Bitmap Rectange
    src_rect = Rect.new(0, 0, cw, ch)
    # Draws Bitmap
    self.contents.blt(0, 0, bitmap, src_rect)
    draw_face("Actor1", 0, 0, 0, size = 96)
    self.contents.draw_text(97, 0, 100, WLH, "Aqui segue uma demo")
    self.contents.draw_text(97, 0, 100, WLH + 36, "de como fazer ")
######################################################################

From now grateful for any help. :thumb:
 
I've never used that feature from MACL (yet) but as I can see, the only thing you have to do is to create the sprite like that:
Code:
@sprite = Sprite_Animation.new(parameters)

"Parameters" must be an Hash with the following keys:
'type', 'loop', 'fs', 'dir', 'frames', 'vp', 'bitmap'.
All these parameters are explained in the script header.

If you don't know how to make an Hash, here's an example:
Code:
hash = {'type' => 'A', 'loop' => true, 'fs' => 10, etc.}

When your sprite is created, you need to set its x and y position to whatever you want like that:
Code:
@sprite.x = 123
@sprite.y = 321
And don't forget to update and dispose your sprite! ;)

Take care!
-Dargor
 
In the next MACL update, I will be making something so you can add a quick animation in your windows and scenes, and it handles the updating and disposing automatically.

I'll check your demo in a bit to see what your problem is.
 
Try this:
Code:
# Window_Display

class Window_Display < Window_Base
 
  def initialize(x, y)
    super (x, y, 544, 150)
    refresh
    @sprite = Sprite_Animation.new({'type' => 'A', 'loop' => true, 'fs' => 0, 'dir' => 'Graphics/teste','vp' => @viewport})
    @sprite.x = 200
    @sprite.y = 100
  end

  def refresh
    self.contents.clear
    # Draws Bitmap
    draw_face("Actor1", 0, 0, 0, size = 96)
    self.contents.draw_text(97, 0, 100, WLH, "Aqui segue uma demo")
    self.contents.draw_text(97, 0, 100, WLH + 36, "de como fazer ")
  end

  def update
    super
    @sprite.update
  end
  
  def dispose
    super
    @sprite.dispose
  end
  
end

I can't try it myself, because I keep getting some cache error. :S
 
Wouldn't your script need some modifications since he's trying to use it with RGSS2?

Edit: Nevermind, I just took a look at the script and the syntax for loading pictures is ok.
 

e

Sponsor

Well, stack level too deep usually has the following possible causes:

Recursivity is being used, and badly; somewhere, somehow, the stack is overflowed by excessive continuous calls.

Or...well, basically it might indicate a loop which has run amok.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top