Main Menu
  • Welcome to The RPG Maker Resource Kit.

[VXA] Extra Movement Frames 1.0.1

Started by modern algebra, September 26, 2012, 12:22:44 AM

0 Members and 1 Guest are viewing this topic.

modern algebra

Extra Movement Frames
Version: 1.0.1
Author: modern algebra
Date: 26 September 2012

Version History




  • <Version 1.0.1> 2012.09.26 - Made a minor change to the code to improve general compatibility
  • <Version 1.0.0> 2012.09.25 - Original Release

Description



This script allows you to import character sprites with more than 3 frames for movement animation. In other words, it allows you to animate sprites a little more smoothly. One use for it is it allows RMXP format characters to be imported directly into a VXA game without editing (although you will need to rename the file).

Features


  • Unlimited number of frames on a sprite to sprite basis
  • Easy to set a custom idle frame and pattern
  • Useful for larger sprites and for smoother animation
  • Fairly easy to use.

Screenshots


Sample with an XP character named "$003-Fighter03%(4)"

Instructions

Paste the script into its own slot in the Script Editor, above Main but below Materials. If you are using my Composite Graphics script, then this script must be placed in a slot below Composite Graphics.

To create a sprite with extra movement frames, all you need to do is rename the character graphic to something of the form:

      Regular_Name%(n)
        where:
          n is the number of frames in each character sprite
 
  EXAMPLES:

  • $001-Fighter01%(4)
    This graphic is a single character with four frames of animation. [XP]
  • 022-Actors12%(6)
    This graphic would be interpreted as a character sheet of 8 characters, each having six frames of animation.

For details on how to set idle frames or custom patterns, see the header of the script. Also, square brackets also work, ie. %[n].

Script




#==============================================================================
#    Extra Movement Frames
#    Version: 1.0.1
#    Author: modern algebra (rmrk.net)
#    Date: 26 September 2012
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#   
#    This script allows you to import character sprites with more than 3 frames
#  for movement animation. In other words, it allows you to animate sprites a
#  little more smoothly. One use for it is it allows RMXP format characters to
#  be imported directly into a VXA game without editing (although you will need
#  to rename the file).
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#   
#    Paste this script into its own slot in the Script Editor, above Main but
#   below Materials. If you are using my Composite Graphics script, then this
#   script must be placed in a slot below Composite Graphics.
#
#    To create a sprite with extra movement frames, all you need to do is
#   rename the character graphic to something of the form:
#
#      Regular_Name%(x)
#        where:
#          x is the number of frames in each character sprite

#  EXAMPLES:
#
#    $001-Fighter01%(4)
#      This graphic is a single character with four frames of animation. [XP]
#    022-Actors12%(6)
#      This graphic would be interpreted as a character sheet of 8 characters,
#      each having six frames of animation.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#    Additionally, this script also allows you to specify the "idle" frame (the
#   frame where the sprite is not moving), and also the pattern if wish to so
#   specify. In essence, all you need to do is add those integers after the
#   number of frames:
#
#      Regular_Name%(x y1 y2 y3 ... yx)
#        where:
#          x is the number of frames in each character sprite
#          y1 is the idle frame (the frame shown when sprite is not moving)
#          y2 ... yx are the pattern.
#
#   Keep in mind that the first frame in a sprite is index 0, the second frame
#   is index 1, etc.
#
#    Where y1 is excluded, it is assumed to be 0. Where y2 ... yx are excluded,
#   the pattern is assumed to simply cycle through the frames one by one until
#   it repeats.
#
#  EXAMPLES:
#
#    $003-Fighter03%(4 2)
#      This graphic is a single character with four frames of animation. The
#      idle frame is 2 (the third one over). The pattern when moving would be
#      2 3 0 1, 2 3 0 1, etc.
#    032-People05%(4 0 1 0 3 2 1)
#      This graphic would be interpreted as a character sheet of 8 characters,
#      each having four frames of animation. The idle frame is 0 (the first
#      in the sheet), and the pattern is 0 1 0 3 2 1, 0 1 0 3 2 1, etc.
#==============================================================================

$imported = {} unless $imported
$imported[:MA_ExtraMovementFrames] = true

#==============================================================================
# *** MA_ExtraMovementFrames
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  This module holds a method for calculating width and height of an emf
# character frame
#==============================================================================

module MA_ExtraMovementFrames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Check if Character has extra movement frames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def ma_char_is_emf_sprite?(character_name)
    character_name && !character_name[/\%[\(\[].+?[\)\]]/].nil?
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Derive Frames Array
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maemf_get_frames(character_name)
    character_name = "" unless character_name
    frames = !character_name[/\%[\(\[](.+?)[\)\]]/] ? [] :
      $1.scan(/\d+/).collect { |s| s.to_i }
    frames[0] = 3 unless frames[0] # If empty, then set to default 3
    frames.push(1, 2, 1, 0) if frames[0] == 3 && frames.size < 2
    frames[1] = 0 unless frames[1] # Set idle frame
    if frames.size < 3
      # Create pattern
      (frames[0] - 1).times {|i| frames.push((frames[1] + i + 1) % frames[0]) }
    end
    return frames
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Calculate Frame Size
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maemf_calc_frame_size(character_name, bitmap, frames = [])
    character_name = "" unless character_name
    frames = maemf_get_frames(character_name) if frames.empty?
    cw = bitmap.width / (frames[0] ? frames[0] : 3)
    ch = bitmap.height / 4
    sign = character_name[/^[\!\$]./]
    if !sign || !sign.include?('$')
      cw /= 4
      ch /= 2
    end
    return cw, ch
  end
end

# Compatibility with Composite Graphics
if $imported[:MA_CompositeGraphics]
  #============================================================================
  # *** Cache
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  #  Summary of Changes:
  #    aliased method - macgve_make_unique_name
  #============================================================================
  class << Cache
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Make Unique Name
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias macgemf_uniqname_3tc8 macgve_make_unique_name
    def macgve_make_unique_name(cg_array = [], *args)
      result = macgemf_uniqname_3tc8(cg_array, *args) # Call Original Method
      # Add %(x) code to name if the first graphic in the array contains it.
      result += $1 if cg_array[0] && cg_array[0].filename[/(\%[\(\[].+?[\)\]])/]
      result
    end
  end
end

#==============================================================================
# ** Game_CharacterBase
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - straighten; update_anime_pattern; initialize;
#      set_graphic; character_name=
#    new methods - maemf_init_char_frames
#==============================================================================

class Game_CharacterBase
  include MA_ExtraMovementFrames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Straighten
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maemf_straghtn_5sb3 straighten
  def straighten(*args, &block)
    maemf_straghtn_5sb3(*args, &block) # Run original method
    @pattern = @original_pattern if @walk_anime || @step_anime
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Anime Pattern
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maemf_updanim_ptrn_2yv5 update_anime_pattern
  def update_anime_pattern(*args)
    if @ma_char_is_emf_sprite # If an emf sprite
      if !@step_anime && @stop_count > 0 # Reset to stationary
        @maemf_frame_index = 0
        @pattern = @original_pattern
      else
        # Next Pattern
        @maemf_frame_index = (@maemf_frame_index + 1) % @maemf_character_pattern.size
        @pattern = @maemf_character_pattern[@maemf_frame_index]
      end
    else
      maemf_updanim_ptrn_2yv5(*args) # Call original method
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Initialize Character Frames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maemf_init_char_frames
    @maemf_frame_index = 0 # Initialize Index
    # Save this value for faster reference
    @ma_char_is_emf_sprite = ma_char_is_emf_sprite?(character_name)
    if @ma_char_is_emf_sprite
      # Get pattern
      @maemf_character_pattern = maemf_get_frames(character_name)
      @maemf_character_pattern.shift # Remove frame number
      @original_pattern = @maemf_character_pattern[0]
    else
      @maemf_character_pattern = []
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Initialize Character Frames Proc
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def self.maemf_init_char_frames_proc
    Proc.new { |method_name|
      alias_method(:"maemf_#{method_name}_2ev9", method_name) # Alias
      define_method(method_name) do |*args| # Define method
        send(:"maemf_#{method_name}_2ev9", *args) # Call original method
        maemf_init_char_frames
      end
    }
  end
  proc = maemf_init_char_frames_proc
  [:initialize, :set_graphic].each { |name| proc.call(name) }
end

#==============================================================================
# ** Game_Player/Follower/Vehicle/Event
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  This aliases methods in these classes that change @character_name in order
# to call maemf_init_char_frames
#==============================================================================

class Game_Player
  # Refresh
  maemf_init_char_frames_proc.call(:refresh)
end

class Game_Follower
  # Refresh
  maemf_init_char_frames_proc.call(:refresh)
end

class Game_Vehicle
  # Load System Settings
  maemf_init_char_frames_proc.call(:load_system_settings)
end

class Game_Event 
  proc = maemf_init_char_frames_proc
  # Clear Page Settings & Setup Page Settings
  [:clear_page_settings, :setup_page_settings].each { |name| proc.call(name) }
end

#==============================================================================
# ** Sprite_Character
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - set_character_bitmap; update_src_rect
#    new methods - ma_set_emf_character_bitmap; ma_update_emf_src_rect
#==============================================================================

class Sprite_Character
  include MA_ExtraMovementFrames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Character Bitmap
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maemf_setcharbmp_4rm6 set_character_bitmap
  def set_character_bitmap(*args)
    @emf_char = ma_char_is_emf_sprite?(@character_name)
    @emf_char ? ma_set_emf_character_bitmap : maemf_setcharbmp_4rm6(*args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Transfer Origin Rectangle
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maemf_updtsrcrect_2kq5 update_src_rect
  def update_src_rect(*args)
    @emf_char ? ma_update_emf_src_rect : maemf_updtsrcrect_2kq5(*args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Character Bitmap
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def ma_set_emf_character_bitmap
    self.bitmap = Cache.character(@character_name)
    @emf_char_frames = maemf_get_frames(@character_name)
    @cw, @ch = maemf_calc_frame_size(@character_name, bitmap, @emf_char_frames)
    self.ox = @cw / 2
    self.oy = @ch
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Transfer Origin Rectangle
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def ma_update_emf_src_rect
    if @tile_id == 0
      index = @character.character_index
      pattern = @character.pattern < @emf_char_frames[0] ? @character.pattern : @emf_char_frames[1]
      sx = (index % 4 * @emf_char_frames[0] + pattern) * @cw
      sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
  end
end

#==============================================================================
# ** Window_Base
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - draw_character
#    new method - ma_draw_emf_character
#==============================================================================

class Window_Base
  include MA_ExtraMovementFrames
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Draw Character Graphic
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maemf_drawcharct_3kq6 draw_character
  def draw_character(character_name, *args)
    character_name[/\%[\(\[].+?[\)\]]/] ? ma_draw_emf_character(character_name, *args) :
      maemf_drawcharct_3kq6(character_name, *args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Draw Extra Movement Frames Character Graphic
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def ma_draw_emf_character(character_name, character_index, x, y)
    return unless character_name
    if !ma_char_is_emf_sprite?(character_name)
      # Draw regular if there is no frame specification in the name
      maemf_drawcharct_3kq6(character_name, *args)
    else
      bitmap = Cache.character(character_name)
      frames = maemf_get_frames(character_name)
      cw, ch = maemf_calc_frame_size(character_name, bitmap, frames)
      n = character_index
      src_rect = Rect.new((n%4*frames[0]+frames[1])*cw, (n/4*4)*ch, cw, ch)
      contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
    end
  end
end


Credit




  • modern algebra

Support



Please post in this topic if you have any questions, suggestions, or error reports.

Known Compatibility Issues

If you are using this script with my Composite Graphics script, then you will need to paste this script below it in the Script Editor. Additionally, you will need to ensure that all composite graphics pasted into a character have the same number of frames. So long as those two conditions are met, however, this script is compatible with Composite Graphics.

Author's Notes



I've never really been fond of this script's design, but I lack the ingenuity to fix it :(. Anyway, this was the first script I wrote for RMVX, and I hope it is useful for some of you.

Terms of Use



I adopt RMRK's default Terms of Use.

cozziekuns

An old classic! Pretty impressive that this was the first script you decided to tackle during the experimental VX stage.

If you don't mind me asking, what exactly about this script don't you like?

modern algebra

I just feel like I should be able to do it better. I can't find any rational way around overwriting several significant methods, which makes compatibility with other sprite-changing scripts annoying, to say the least. Further, this script doesn't accomodate for any script which changes the value of @character_name in a non-traditional method or way. I could have fixed that by putting something in an update method observing changes, but that felt ugly, so I made the Proc-creating class method for easy compatibility patching. Even for that, though I feel like I was being lazy. The naming convention is also kind of non-intuitive, which I feel might dissuade people from using the script.

Anyway, it's just one of those scripts where I intuitively sense a significant discrepancy between my coding and the best possible coding (all my scripts have some discrepancy, naturally), and I'm not good enough to see where I'm going wrong. And I find that frustrating.

arktheseer

Is there a way to do an animation by selecting different framenumbers somehow?

For example the original animation goes like: 0,1,2,3,4,5
And I want to do an animation like this: 0,1,2,4,3,5
Or just a stopped frame: 4 (but the normal animation wouldn't start on frame 4)

I really just want to be able to select a particular frame in the animation via a script snippet.

So is there a way to do this?

Sorry for my explanation if it was "confusing".

modern algebra

There isn't, but that would be a logical thing to add to the script.

arktheseer

Thanks! ** went to the Script Requestes forum** :)

Acolyte

Is there a way to increase the animation speed?

modern algebra

No, there isn't. Sorry. It would have made sense to add a feature like that.

Acolyte


kadena1984

Is it possible not to include the idle frame for the walking sequenze ?

Example:
Test06%(4 0 1 2 3)
The idle frame is 0, and the pattern is 1 2 3, 1 2 3 etc.

I know this is an quite old post but it would be great to get an replay, i was looking for such a script for days now and this is the one i got to work for being so damn easy to use ^_^
So i appreciate any help i could get

modern algebra

No, sorry, not as the script is currently structured.

It would likely not be hard to change that, but I am afraid I don't have much time for scripting these days. Sorry. If you can find someone else to do it though, then that person has my permission to modify and republish my script.

kadena1984

Ok i do that, tnx for your replay and for making this great script ^_^

tikie

Can you help me what to do next after copy and paste this script above main and under material in Editor Script of RPG ACE VX ?

Now i have a spritesheet include 4 frames and 4 directions, after import it to rpg maker ace vx, it only detect 3 frames.

In case it only affect 4 frames in game by this script , how do i calculate exactly what size per cell (width x height) and max size of the bitmap is imported ?

&&&&&&&&&&&&&

The script won't affect how resources are used.

Your sprite is named $walk 1
When it should be named $walk%(4)

The instructions go into better detail about the naming process.

#  Instructions:
#   
#    Paste this script into its own slot in the Script Editor, above Main but
#   below Materials. If you are using my Composite Graphics script, then this
#   script must be placed in a slot below Composite Graphics.
#
#    To create a sprite with extra movement frames, all you need to do is
#   rename the character graphic to something of the form:
#
#      Regular_Name%(x)
#        where:
#          x is the number of frames in each character sprite

#  EXAMPLES:
#
#    $001-Fighter01%(4)
#      This graphic is a single character with four frames of animation. [XP]
#    022-Actors12%(6)
#      This graphic would be interpreted as a character sheet of 8 characters,
#      each having six frames of animation.
&&&&&&&&&&&&&&&&

tikie

Thanks you , but after i put it name similar to the guide, i wonder what size per cell which has 1 sprite action.

I have import a image 512x512 to database, and after rename, put the script in, i still don't know how this script work , i mean, i need to know : after import a spritesheet size 512x512 into database, i need character do 4 actions but i don't know it how it calculator size per cell,if i know, so i can repaint my spritesheet character action

&&&&&&&&&&&&&

Please upload your sprite so I can look at it.
&&&&&&&&&&&&&&&&

tikie

thanks for reply, here is my sprite :

&&&&&&&&&&&&&

#17
Not sure what's wrong.
I plugged in the script, and imported the sprite and it works fine.


Are you using rpg maker VX or rpg maker VX ACE?
Are you importing it and not just dropping it into the folder?
&&&&&&&&&&&&&&&&

tikie

I'm using RPG maker VX ACE , i import it to database, not copy it  ;9

Acolyte

Modern, I'm not sure if your posting more is a reliable indicator of you having sufficient time for scripting, but I would really appreciate it if you could update this for my new RTP sprites. <3

&&&&&&&&&&&&&

&&&&&&&&&&&&&&&&

Acolyte

Quote from: kadena1984 on February 14, 2015, 04:02:20 PM
Is it possible not to include the idle frame for the walking sequenze ?

Example:
Test06%(4 0 1 2 3)
The idle frame is 0, and the pattern is 1 2 3, 1 2 3 etc.

I know this is an quite old post but it would be great to get an replay, i was looking for such a script for days now and this is the one i got to work for being so damn easy to use ^_^
So i appreciate any help i could get
Quote from: Acolyte on November 19, 2014, 12:50:55 AM
Is there a way to increase the animation speed?

konb

Sorry to bring this back from the dead, but I'm going to be using this script in a commercial, I sent you a Pm, but it seems its been a while since you last logged in. Thank you for making this script! And sorry for using it even though I can't get your permission.