In short these animation sprites are bound to the character it is playing on's screen_x and screen_y now in RPG Maker VX it works perfectly and the screen_x and screen_y is calculated really strange.
#-------------------------------------------------------------------------- # * Get Screen X-Coordinates - RPG Maker VX Default Code #-------------------------------------------------------------------------- def screen_x return ($game_map.adjust_x(@real_x) + 8007) / 8 - 1000 + 16 endIn VX Ace the same code reads:
#-------------------------------------------------------------------------- # * Get Screen X-Coordinates #-------------------------------------------------------------------------- def screen_x $game_map.adjust_x(@real_x) * 32 + 16 end So when the map scrolls the animation will sway with the map movement (though it stays with the event it's on). The map movement sway is absolutely unacceptable for what I'm using this stuff for. Curious as to whether or not anyone has a solution for this. Feel free to pop my animation class in a project and give it a go.
Phil's class Animation:
Code:
class Game_Character attr_accessor :character_animations alias chrctr_animation_initialize initialize unless $@ def initialize chrctr_animation_initialize @character_animations = [] end alias chrctr_animation_update update unless $@ def update chrctr_animation_update if !@character_animations.empty? for anim in @character_animations if !anim.nil? && anim.running? anim.update if anim.is_a?(Animation) end end end end def start_animation(id) return if @character_animations.nil? animation = Animation.new(self, id) @character_animations.push(animation) end endclass Spriteset_Map alias spritemap_animation_dispose dispose unless $@ def dispose for event in $game_map.events.values for animation in event.character_animations if animation.is_a?(Animation) && animation.running? animation.dispose animation = nil end end event.character_animations = [] end for animation in $game_player.character_animations if animation.is_a?(Animation) && animation.running? animation.dispose animation = nil end end $game_player.character_animations = [] spritemap_animation_dispose end endclass Animation def initialize(character, id) return if SceneManager.scene.spriteset.viewport1.nil? || !SceneManager.scene.spriteset.viewport1.visible || !SceneManager.scene.spriteset.viewport1.is_a?(Viewport) return if $data_animations[id].nil? @disposed = false @viewport = SceneManager.scene.spriteset.viewport1 @character = character @animation = $data_animations[id] @rate = 4 @duration = @animation.frame_max * @rate + 1 @ani_bit1 = Cache.animation(@animation.animation1_name, @animation.animation1_hue) @ani_bit2 = Cache.animation(@animation.animation2_name, @animation.animation2_hue) Graphics.frame_reset @ani_spr = [] 16.times do sprite = ::Sprite.new(SceneManager.scene.spriteset.viewport1) sprite.visible = false @ani_spr.push(sprite) end if @animation.position == 3 if @viewport.nil? @ani_ox = Graphics.width / 2 @ani_oy = Graphics.height / 2 else @ani_ox = @viewport.rect.width / 2 @ani_oy = @viewport.rect.height / 2 end else @ani_ox = @character.screen_x @ani_oy = @character.screen_y if @animation.position == 0 @ani_oy -= 32 / 2 elsif @animation.position == 2 @ani_oy += 32 / 2 end end end def running? return !@disposed end def update return if @disposed @duration -= 1 if @animation.position == 3 if SceneManager.scene.spriteset.viewport1.nil? @ani_ox = Graphics.width / 2 @ani_oy = Graphics.height / 2 else @ani_ox = SceneManager.scene.spriteset.viewport1.rect.width / 2 @ani_oy = SceneManager.scene.spriteset.viewport1.rect.height / 2 end else @ani_ox = @character.screen_x @ani_oy = @character.screen_y if @animation.position == 0 @ani_oy -= 32 / 2 elsif @animation.position == 2 @ani_oy += 32 / 2 end end if @duration % @rate == 0 if @duration > 0 frame_index = @animation.frame_max frame_index -= (@duration + @rate - 1) / @rate update_sprites(@animation.frames[frame_index]) @animation.timings.each do |timing| animation_process_timing(timing) if timing.frame == frame_index end else end_animation end end end def end_animation @disposed = true if !@ani_spr.nil? for sprite in @ani_spr if !sprite.nil? && !sprite.disposed? sprite.dispose sprite = nil end end end @ani_spr = nil end def dispose @disposed = true if !@ani_spr.nil? for sprite in @ani_spr if !sprite.nil? && !sprite.disposed? sprite.dispose sprite = nil end end end @ani_bit1.dispose if !@ani_bit1.nil? && !@ani_bit1.disposed? @ani_bit2.dispose if !@ani_bit2.nil? && !@ani_bit2.disposed? @ani_spr = nil @ani_bit1 = nil @ani_bit2 = nil end def update_sprites(frame) cell_data = frame.cell_data for i in 0..15 sprite = @ani_spr[i] next if sprite.nil? next if sprite.disposed? pattern = cell_data[i, 0] if !pattern || pattern < 0 sprite.visible = false next end sprite.bitmap = pattern < 100 ? @ani_bit1 : @ani_bit2 sprite.visible = true sprite.src_rect.set(pattern % 5 * 192, pattern % 100 / 5 * 192, 192, 192) sprite.x = @ani_ox + cell_data[i, 1] sprite.y = @ani_oy + cell_data[i, 2] sprite.angle = cell_data[i, 4] sprite.mirror = (cell_data[i, 5] == 1) sprite.z = 600 + i sprite.ox = 96 sprite.oy = 96 sprite.zoom_x = cell_data[i, 3] / 100.0 sprite.zoom_y = cell_data[i, 3] / 100.0 sprite.opacity = cell_data[i, 6] sprite.blend_type = cell_data[i, 7] p sprite.x if sprite.x != @ani_ox end#~ @ani_spr.each_with_index do |sprite, i|#~ next unless sprite#~ pattern = cell_data[i, 0]#~ if !pattern || pattern < 0#~ sprite.visible = false#~ next#~ end#~ sprite.bitmap = pattern < 100 ? @ani_bit1 : @ani_bit2#~ sprite.visible = true#~ sprite.src_rect.set(pattern % 5 * 192, pattern % 100 / 5 * 192, 192, 192)#~ sprite.x = @ani_ox + cell_data[i, 1]#~ sprite.y = @ani_oy + cell_data[i, 2]#~ sprite.angle = cell_data[i, 4]#~ sprite.mirror = (cell_data[i, 5] == 1)#~ sprite.z = 600 + i#~ sprite.ox = 96#~ sprite.oy = 96#~ sprite.zoom_x = cell_data[i, 3] / 100.0#~ sprite.zoom_y = cell_data[i, 3] / 100.0#~ sprite.opacity = cell_data[i, 6]#~ sprite.blend_type = cell_data[i, 7]#~ end end def animation_process_timing(timing) timing.se.play case timing.flash_scope when 1 #self.flash(timing.flash_color, timing.flash_duration * @ani_rate) when 2 if @viewport @viewport.flash(timing.flash_color, timing.flash_duration * @rate) end when 3 #self.flash(nil, timing.flash_duration * @rate) end end end