Project1

标题: 使用动画叠加脚本产生的动画错位问题(已安装补丁VXAce_SP... [打印本页]

作者: 宝开君    时间: 2025-3-23 18:37
标题: 使用动画叠加脚本产生的动画错位问题(已安装补丁VXAce_SP...
本帖最后由 宝开君 于 2025-3-24 15:23 编辑

各位大佬,我在做一款ARPG游戏,由于其中敌人(事件)的受击与攻击等都是由动画完成,所以本人安装了一个动画叠加脚本来方便显示。但发现安装脚本后如果动画叠加,后出现的动画会产生错位(与事件位置不绑定,地图卷动时会产生错位)。故请教各位大佬有什么好的解决方法。
以下是脚本内容:
  1. # =============================================================================
  2. # TheoAllen - Multiple Animations Display
  3. # Version : 1.1
  4. # Contact : Discord: @Theo#3034 / Twitter: @theolized
  5. # -----------------------------------------------------------------------------
  6. # Requested by : LadyMinerva
  7. # =============================================================================
  8. ($imported ||= {})[:Theo_MultiAnime] = true
  9. # =============================================================================
  10. # Change Logs:
  11. # -----------------------------------------------------------------------------
  12. # 2018.12.02 - Added feature to play multiple animations in map consecutively
  13. #              by using show animation in eventing.
  14. # 2014.06.25 - Ported from TSBS addons. Now can be used independently
  15. #            - Got rid some unused codes
  16. # 2014.06.23 - Multiple animation on animation guard
  17. # 2014.05.13 - Fixed wrong animation flash target
  18. # 2014.05.02 - Finished script
  19. # =============================================================================
  20. =begin

  21.   -------------------------------------------------------------------
  22.   Introduction :
  23.   By default, the animation only can hold up to 16 pictures. It's sometimes
  24.   prevent you to do some crazy animations. By adding this script, now you can
  25.   merge two different animations, mix them in a single animation call. However,
  26.   you still can not see them in editor at once. So, use your imagination =D
  27.   
  28.   -------------------------------------------------------------------
  29.   How to use :
  30.   Put this script below material but above main.
  31.   
  32.   There're two ways to setting up animation. The first way is to deal with
  33.   the configuration below. The second one is to add notetag in animation name
  34.   since there's no notebox in animation database.
  35.   
  36.   The notetag is
  37.   <link: id,id,id>
  38.   
  39.   id is an animation id that will be linked / merged to current animation. You
  40.   may add it as many as you want.
  41.   
  42.   -------------------------------------------------------------------
  43.   Terms of use :
  44.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  45.   as you don't claim it yours. For commercial purpose, don't forget to give me
  46.   a free copy of the game.  

  47. =end
  48. # =============================================================================
  49. # Configuration
  50. # =============================================================================
  51. module Theo
  52.   module MultiAnime
  53.     # ------------------------------------------------------------------------
  54.     # In script configuration. Record the animation links here. You make put
  55.     # multiple animation link by put them in array / inside [].
  56.     #
  57.     # Format :
  58.     # anim_id => link,
  59.     # anim_id => [link1, link2, link3],
  60.     #
  61.     # Anim_id is animation in database as a base which hold animation links
  62.     # to call other animation. Don't forget to add comma!
  63.     # ------------------------------------------------------------------------
  64.       AnimeList = {   
  65.         #89 => 92,
  66.         # Add more here
  67.         
  68.       } # <-- dont touch
  69.     # ------------------------------------------------------------------------
  70.    
  71.     # ------------------------------------------------------------------------
  72.     # Regular expression to read the notetag in animation name in database.
  73.     # Do not touch if you don't understand Ruby REGEXP
  74.       Regex = /<link\s*:\s*(.+)>/i
  75.     # ------------------------------------------------------------------------
  76.   end
  77. end
  78. #==============================================================================
  79. # End Configuration
  80. #==============================================================================
  81. class RPG::Animation
  82.   
  83.   def anime_links
  84.     return @anime_links if @anime_links
  85.     @anime_links = []
  86.     if name[Theo::MultiAnime::Regex]
  87.       $1.split(/,/).each do |anim_id|
  88.         @anime_links.push(anim_id.to_i)
  89.       end
  90.     end
  91.     return @anime_links
  92.   end
  93.   
  94. end
  95. #==============================================================================
  96. # Sprite multiple animation
  97. #------------------------------------------------------------------------------
  98. class Sprite_MultiAnime < Sprite_Base
  99.   
  100.   def initialize(viewport, ref_sprite, anime, flip = false)
  101.     super(viewport)
  102.     @ref_sprite = ref_sprite
  103.     update_reference_sprite
  104.     start_animation(anime, flip)
  105.   end
  106.   
  107.   def update
  108.     update_reference_sprite
  109.     super
  110.     dispose if !animation?
  111.   end
  112.   
  113.   def update_reference_sprite
  114.     src_rect.set(@ref_sprite.src_rect)
  115.     self.ox = @ref_sprite.ox
  116.     self.oy = @ref_sprite.oy
  117.     self.x = @ref_sprite.x
  118.     self.y = @ref_sprite.y
  119.     self.z = @ref_sprite.z
  120.   end
  121.   
  122.   # Overwrite animation process timing
  123.   def animation_process_timing(timing)
  124.     timing.se.play unless @ani_duplicated
  125.     case timing.flash_scope
  126.     when 1
  127.       @ref_sprite.flash(timing.flash_color, timing.flash_duration * @ani_rate)
  128.     when 2
  129.       if viewport && !@ani_duplicated
  130.         viewport.flash(timing.flash_color, timing.flash_duration * @ani_rate)
  131.       end
  132.     when 3
  133.       @ref_sprite.flash(nil, timing.flash_duration * @ani_rate)
  134.     end
  135.   end
  136.   
  137. end
  138. #==============================================================================
  139. # Sprite Battler
  140. #------------------------------------------------------------------------------
  141. class Sprite_Battler
  142.   attr_reader :multianimes
  143.   
  144.   alias theo_multianim_init initialize
  145.   def initialize(viewport, battler = nil)
  146.     @multianimes = []
  147.     theo_multianim_init(viewport, battler)
  148.   end
  149.   
  150.   alias theo_multianime_start_anim start_animation
  151.   def start_animation(anime, flip = false)
  152.     if @animation
  153.       spr_anim = Sprite_MultiAnime.new(viewport, self, anime, flip)
  154.       multianimes.push(spr_anim)
  155.     else
  156.       theo_multianime_start_anim(anime, flip)
  157.       multianime = @animation.anime_links
  158.       check_multi = Theo::MultiAnime::AnimeList[@animation.id]
  159.       if check_multi.is_a?(Array)
  160.         multianime += check_multi
  161.       elsif check_multi
  162.         multianime += [check_multi]
  163.       end
  164.       multianime.each do |ma|
  165.         start_animation($data_animations[ma], flip)
  166.       end
  167.     end
  168.   end
  169.   
  170.   alias theo_multianim_update update
  171.   def update
  172.     theo_multianim_update
  173.     multianimes.delete_if do |anime|
  174.       anime.update
  175.       anime.disposed?
  176.     end
  177.   end
  178.   
  179.   alias theo_multianim_dispose dispose
  180.   def dispose
  181.     theo_multianim_dispose
  182.     multianimes.each do |anime|
  183.       anime.dispose
  184.     end
  185.   end
  186.   
  187.   def animation?
  188.     @animation || !multianimes.empty?
  189.   end
  190.   
  191.   alias theo_multianime_update_anim update_animation
  192.   def update_animation
  193.     return unless @animation
  194.     theo_multianime_update_anim
  195.   end
  196.   
  197. end
  198. #==============================================================================
  199. # Sprite Character
  200. #------------------------------------------------------------------------------
  201. class Sprite_Character
  202.   attr_reader :multianimes
  203.   
  204.   alias theo_multianim_init initialize
  205.   def initialize(viewport, char = nil)
  206.     @multianimes = []
  207.     theo_multianim_init(viewport, char)
  208.   end
  209.   
  210.   alias theo_multianime_start_anim start_animation
  211.   def start_animation(anime, flip = false)
  212.     if @animation
  213.       spr_anim = Sprite_MultiAnime.new(viewport, self, anime, flip)
  214.       multianimes.push(spr_anim)
  215.     else
  216.       theo_multianime_start_anim(anime, flip)
  217.       multianime = @animation.anime_links
  218.       check_multi = Theo::MultiAnime::AnimeList[@animation.id]
  219.       if check_multi.is_a?(Array)
  220.         multianime += check_multi
  221.       elsif check_multi
  222.         multianime += [check_multi]
  223.       end
  224.       multianime.each do |ma|
  225.         start_animation($data_animations[ma], flip)
  226.       end
  227.     end
  228.   end
  229.   
  230.   alias theo_multianim_update update
  231.   def update
  232.     theo_multianim_update
  233.     multianimes.delete_if do |anime|
  234.       anime.update
  235.       anime.disposed?
  236.     end
  237.   end
  238.   
  239.   alias theo_multianim_dispose dispose
  240.   def dispose
  241.     theo_multianim_dispose
  242.     multianimes.each do |anime|
  243.       anime.dispose
  244.     end
  245.   end
  246.   
  247.   def animation?
  248.     @animation || !multianimes.empty?
  249.   end
  250.   
  251.   alias theo_multianime_update_anim update_animation
  252.   def update_animation
  253.     return unless @animation
  254.     theo_multianime_update_anim
  255.   end
  256.   
  257. end
  258. #==============================================================================
  259. # Game Character
  260. #------------------------------------------------------------------------------
  261. class Game_Character
  262.   # Overwrite animation_id=
  263.   def animation_id=(id)
  264.     @animation_id = id
  265.     return if id == 0
  266.     play_animation
  267.   end
  268.   
  269.   def play_animation
  270.     spr = SceneManager.scene.instance_variable_get("@spriteset")
  271.     return unless spr
  272.     spr.find_char(self).start_animation($data_animations[@animation_id])
  273.   end
  274. end
  275. #==============================================================================
  276. # Spriteset Map
  277. #------------------------------------------------------------------------------
  278. class Spriteset_Map
  279.   def find_char(char)
  280.     return @character_sprites.find {|spr| spr.character == char}
  281.   end
  282. end
复制代码




作者: 百里_飞柳    时间: 2025-3-23 18:37
在 VXAce_SP1 的基础上,再给它的多层动画适配一下就好了
  1. class Sprite_Base
  2.   attr_reader   :animation, :ani_sprites
  3.   attr_accessor :ani_ox, :ani_oy
  4. end
  5. class Sprite_Character
  6.   #--------------------------------------------------------------------------
  7.   # ● アニメーションの移動
  8.   #--------------------------------------------------------------------------
  9.   alias vxace_sp1_move_animation_0330 move_animation
  10.   def move_animation(dx, dy)
  11.     vxace_sp1_move_animation_0330(dx, dy)
  12.     multianimes.each do |anime|
  13.       if anime.animation && anime.animation.position != 3
  14.         anime.ani_ox += dx
  15.         anime.ani_oy += dy
  16.         anime.ani_sprites.each do |sprite|
  17.           sprite.x += dx
  18.           sprite.y += dy
  19.         end
  20.       end
  21.     end
  22.   end
  23. end
复制代码

作者: 阵颜    时间: 2025-3-23 19:18
原本的显示动画就有bug,不会跟随事件移动。
后面官方出了一个补丁给修复了。
作者: 宝开君    时间: 2025-3-23 20:55
阵颜 发表于 2025-3-23 19:18
原本的显示动画就有bug,不会跟随事件移动。
后面官方出了一个补丁给修复了。 ...

嗯,我装了那个补丁,但是看来那个补丁对这个脚本不起作用(我试过把脚本放在补丁之上,报错了)。QAQ
作者: 宝开君    时间: 前天 14:52
百里_飞柳 发表于 2025-3-23 18:37
在 VXAce_SP1 的基础上,再给它的多层动画适配一下就好了

谢谢大佬指点——




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1