MultiFrame Sprites
Version 1.0
Introduction
This script allows the user to have any number of sprite frames. RMVXAce and its predecessor only allows 3 frames by 4 directions. This allows any number of frames by 4 directions. Its pretty easy to setup too.
Script
Spoiler
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# MultiFrame Sprites - Ace v1.0
# FenixFyreX
# RPG Maker VxAce
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# This script allows you to setup a symbol, which returns a
# pattern array, idle_frame index, and frame max. These will be applied to all
# sprites with said symbol in their image name.
#
# The % sprite example belongs to Despain, as he made the sprite. Credit for it
# or feel his wrath.
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
module FyxA
module CustomSprites
Patterns = {
# Key => [ pattern_array, idle_frame, frame_max, speeds ],
#
# pattern_array - the order in which each frame is shown
# idle_frame - the frame the sprite sits on when still
# frame_max - the amount of frames overall in the image
# speeds - how fast the sprite cycles through frames running/walking
# If speeds is not present, the default 1.5,1 will be used.
# RMXP shows frame 0, then 1, then 2, then 3. When the sprite is idle, it
# shows frame 2. There are 4 frames total in an rmxp sprite. We also want
# to display these frames a bit faster, so speeds are set to [2.5, 2]
"[-RMXP-]" => [[0,1,2,3], 2, 4, [2.5,2] ],
"[%]" => [[1,2,3,4], 0, 5 ],
}
end
end
class Game_CharacterBase
attr_reader :pattern_index
alias initialize_pat_ind_fyx_mfs initialize unless $@
def initialize(*a,&bl)
@pattern_index = 0
initialize_pat_ind_fyx_mfs(*a,&bl)
@original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
end
alias update_anim_speeds_fyx_mfs update_anime_count
def update_anime_count(*a,&bl)
if mfs_sprite?
s1,s2 = *mfs_sprite?(true)[-1]
if moving? && @walk_anime
@anime_count += s2
elsif @step_anime || @pattern != @original_pattern
@anime_count += s1
end
else
update_anim_speeds_fyx_mfs(*a,&bl)
end
end
alias update_anim_pat_fyx_mfs update_anime_pattern
def update_anime_pattern(*a,&bl)
if mfs_sprite?
key,pattern_array,@original_pattern,fm = *mfs_sprite?(true)
max_frames = pattern_array.include?(@original_pattern) ? fm : fm-1
if !@step_anime && @stop_count > 0
@pattern_index = -1
@pattern = @original_pattern
else
@pattern_index = (@pattern_index + 1) % max_frames
@pattern = pattern_array[@pattern_index]
if (@pattern == @original_pattern) && (!pattern_array.include?(@original_pattern))
@pattern_index = (@pattern_index + 1) % max_frames
@pattern = pattern_array[@pattern_index]
end
end
else
update_anim_pat_fyx_mfs(*a,&bl)
end
end
def mfs_sprite?(ret=false)
FyxA::CustomSprites::Patterns.each_pair do |key,a|
pa,op,fm,sa = *a
if @character_name.include?(key)
sp = sa.nil? ? [1,1.5] : sa
return ret ? [key,pa,op,fm,sp] : true
end
end
return ret ? [nil,[1,2,0],1,3,[1,1.5]] : false
end
end
class Game_Player < Game_Character
alias initialize_plyr_ind_mfs initialize unless $@
def initialize(*a,&bl)
initialize_plyr_ind_mfs(*a,&bl)
@original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
end
alias refresh_mfs refresh
def refresh(*a,&bl)
refresh_mfs
@original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
@pattern = @original_pattern
end
end
class Game_Event < Game_Character
alias initialize_evnt_ind_mfs initialize unless $@
def initialize(*a,&bl)
initialize_evnt_ind_mfs(*a,&bl)
@original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
end
alias refresh_mfs refresh
def refresh(*a,&bl)
refresh_mfs
@original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
@pattern = @original_pattern
end
end
class Sprite_Character < Sprite_Base
alias initialize_player_refresh initialize
def initialize(*a,&bl)
a[-1].refresh if a[-1].is_a?(Game_Player)
initialize_player_refresh(*a,&bl)
end
alias set_char_bmp_mfs set_character_bitmap
def set_character_bitmap(*a,&bl)
if !@character.mfs_sprite?
set_char_bmp_mfs(*a,&bl)
else
key,pattern_array,op,fm = *@character.mfs_sprite?(true)
self.bitmap = Cache.character(@character_name)
sign = @character_name[/^[\!\$]./]
if sign && sign.include?('$')
@cw = bitmap.width / fm
@ch = bitmap.height / 4
else
@cw = bitmap.width / fm*4
@ch = bitmap.height / 8
end
self.ox = @cw / 2
self.oy = @ch
end
end
alias update_src_r_mfs update_src_rect
def update_src_rect(*a,&bl)
if @character.mfs_sprite?
key,pa,op,fm = *@character.mfs_sprite?(true)
max_frames = pa.include?(op) ? fm : fm-1
if @tile_id == 0
index = @character.character_index
pattern = @character.pattern_index < max_frames ? @character.pattern : op
sx = (index % 4 * 3 + pattern) * @cw
sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
else
update_src_r_mfs(*a,&bl)
end
end
endFAQ / Notes
How do I setup a multi-framed sprite?
First, you need to create a sprite pattern in the config part of the script. It's easy and explained there. After that, put the key you gave to your sprite pattern in the filename of your sprite. After that, you're done! The system will now recognize your sprite pattern.
If you have any questions, feel free to ask.
If you use this in your project, don't forget to credit me











