So I'am using a script in my game that adds animated face sprites
it works great but in battles the game lags so much when there's more
than 1 character with an animated face. Also when you use an item the game
lags big time and it lasts through the entire battle. The item thing even
effects when there's only one party member. The game drops from 60 FPS down to 9 FPS in seconds
Can someone please fix this script?
I really need some help.
Thanks!
it works great but in battles the game lags so much when there's more
than 1 character with an animated face. Also when you use an item the game
lags big time and it lasts through the entire battle. The item thing even
effects when there's only one party member. The game drops from 60 FPS down to 9 FPS in seconds
Can someone please fix this script?
I really need some help.
Thanks!
Code:
#===============================================================================
# )----------------------------------------------------------------------------(
# )-- AUTHOR: Mr Trivel --(
# )-- NAME: Animated Faces --(
# )-- CREATED: 2014-09-12 --(
# )-- VERSION: 1.2 --(
#===============================================================================
# )----------------------------------------------------------------------------(
# )-- VERSION HISTORY --(
# )-- 1.0 - Initial script. --(
# )-- 1.1 - Fixed bugs. Uses Frames per second instead of pure frames. --(
# )-- 1.2 - Fixed more bugs. Loops through drawn faces instead of party. --(
#===============================================================================
# )----------------------------------------------------------------------------(
# )-- DESCRIPTION --(
# )-- Allows for actor faces to be animated. --(
#===============================================================================
# )----------------------------------------------------------------------------(
# )-- INSTRUCTIONS --(
# )-- Define animation files and frame sequence in ANIMATED_FACES module. --(
#===============================================================================
# )----------------------------------------------------------------------------(
# )-- LICENSE INFO --(
# )-- Free for non-commercial & commercial games if credit was given to --(
# )-- Mr Trivel. --(
# )----------------------------------------------------------------------------(
#===============================================================================
# )=======---------------------------------------------------------------------(
# )-- Module: ANIMATED_FACES --(
# )---------------------------------------------------------------------=======(
module ANIMATED_FACES
# )--------------------------------------------------------------------------(
# )-- Place your animated faces data here. --(
# )--------------------------------------------------------------------------(
DATA = {
# )-- ACTOR_ID Filename Frame Sequence
1 => [ "Casey_Face.png", [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 6 ,5 ,4, 3, 2, 1, 1, 1, 1, 1,1] ],
2 => [ "Actor2.png", [0, 1, 2, 3, 2, 0, 0, 0, 0, 0 ,0, 0] ]
}
# )--------------------------------------------------------------------------(
# )-- How fast should frames change. Speed in milliseconds. --(
# )--------------------------------------------------------------------------(
FRAME_SPEED = 20
end
# )=======---------------------------------------------------------------------(
# )-- class: Window_Base --(
# )---------------------------------------------------------------------=======(
class Window_Base < Window
include ANIMATED_FACES
alias :mrts_face_anims_update :update
alias :mrts_face_anims_initialize :initialize
# )--------------------------------------------------------------------------(
# )-- Alias: initialize --(
# )--------------------------------------------------------------------------(
def initialize(x, y, width, height)
mrts_face_anims_initialize(x, y, width, height)
@time_now = Time.now
@elapsed_time = 0.0
@actor_hash = {}
end
# )--------------------------------------------------------------------------(
# )-- Overwrite: draw_actor_face --(
# )--------------------------------------------------------------------------(
def draw_actor_face(actor, x, y, enabled = true)
data = DATA[actor.id]
if data
@animated_actors ||= true
@actor_hash[actor.id] ||= 0
face_name = data[0]
face_index = data[1][@actor_hash[actor.id]]
draw_face(face_name, face_index, x, y, enabled)
else
draw_face(actor.face_name, actor.face_index, x, y, enabled)
end
end
# )--------------------------------------------------------------------------(
# )-- Alias: update --(
# )--------------------------------------------------------------------------(
def update
finish = Time.now
@elapsed_time += ms(@time_now, finish)
mrts_face_anims_update
if @animated_actors && @elapsed_time >= FRAME_SPEED && Time.now.to_f != @time_now
@actor_hash.each { |k, v|
next unless @actor_hash[k]
@actor_hash[k] += 1
@actor_hash[k] = 0 if @actor_hash[k] > DATA[k][1].size-1
}
refresh
@elapsed_time = 0
end
@time_now = Time.now
end
# )--------------------------------------------------------------------------(
# )-- New Method: ms --(
# )--------------------------------------------------------------------------(
def ms(start, finish)
(finish - start) * 1000.0
end
end
