04-15-2014, 11:40 AM
i found a way to get the the animation cell's on screen duration from the file name itself and cycle through an array of all matching file names of an animation set.
here is a video of it working:
code improvements?
it does what i want BUT waIT! i seriously would enjoy some suggestions before i request this to close. :)
here is a video of it working:
Content Hidden
code improvements?
Content Hidden
Code:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Show Picture
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias mafpm_showpic_3jb7 show
def show(name, *args, &block)
# Only fix pictures if in Scene_Map
if SceneManager.scene_is?(Scene_Map)
@mafpm_fixed = (MA_FixPicture::SWITCH_ID == true ||
$game_switches[MA_FixPicture::SWITCH_ID] || !name[/\[FIXED\]/i].nil?)
z_var = $game_variables[MA_FixPicture::Z_VARIABLE_ID]
# If 0 or less than 300, then it should belong to the viewport1
@mafpm_vp_id = z_var < 300 ? 1 : 2
@mafpm_z = z_var
end
mafpm_showpic_3jb7(name, *args, &block) # Call Original Method
if @mafpm_fixed && (MA_FixPicture::COORDINATES_SWITCH_ID == true || $game_switches[MA_FixPicture::COORDINATES_SWITCH_ID])
@x *= 32
@y *= 32
end
#if shown picture name contains [ANI][frame index] & [display length]..
if @name[/(\w+)(\[ANI\])\[(\d+)\]\[(\d+)\]/i] # to create (local $variables)
base_name = $1
@mafpm_ani_duration = $4.to_i # $4 is the "frame duration" regexp match
@on_screen = @mafpm_ani_duration # @on_screen is a disposable copy of $4
@mafpm_frame_index = 0 # to mark current possition in "Dir.entries[]"
@mafpm_ani_frames = Dir.entries(
"Graphics/Pictures").select{
|e| e =~ /#{Regexp.quote(base_name)}(\[ANI\])\[(\d+)\]\[(\d+)\]/i}
@mafpm_animated = true # trigger update to animate
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Picture
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias trpls_gp_update_als update
def update
trpls_gp_update_als
update_animation if @mafpm_animated # <-- the trigger from "def show"
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Animate Picture if [ANI] appended to picture filename
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def update_animation
@on_screen -= 1 #reduce time to display current frame
if @on_screen == 0
if @mafpm_frame_index != (@mafpm_ani_frames.size - 1)
@mafpm_frame_index += 1
@name = @mafpm_ani_frames[@mafpm_frame_index]
@name[/(\w+)(\[ANI\])\[(\d+)\]\[(\d+)\]/i] # to create (local $variables)
@on_screen = $4.to_i
else #(if there is no more frames in @mafpm_ani_frames array)
@mafpm_frame_index = 0 # return to original frame(picture)
@name = @mafpm_ani_frames[0]
@on_screen = @mafpm_ani_duration # <-- original frame duration
end
end
end
it does what i want BUT waIT! i seriously would enjoy some suggestions before i request this to close. :)