查看: 1681|回复: 3

[已经解决] 脚本搞不懂请大神帮帮忙技能动画和状态动画的上下层关系

[复制链接]
梦石
0
星屑
60
在线时间
32 小时
注册时间
2009-3-19
回帖
6
发表于 2017-8-15 18:02:40 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 mmmlqaz 于 2017-8-15 18:09 编辑

状态动画一直在技能动画前面!求技能动画在上层!!!!!大佬帮忙看看。。
  1. #==============================================================================
  2. #
  3. # �� Yanfly Engine Ace - State Animations v1.01
  4. # -- Last Updated: 2014.03.22
  5. # -- Level: Normal   在状态栏里备注显示的动画:   <state ani: X>
  6. # -- Requires: n/a
  7. # -- Special Thanks:
  8. #    SoulPour777 for the Bug Fix for V1.01
  9. #==============================================================================

  10. $imported = {} if $imported.nil?
  11. $imported["YEA-StateAnimations"] = true

  12. #==============================================================================
  13. # �� Updates
  14. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. # 2014.03.22 - Some of the animations have been using the same reference count,
  16. #              which results to cancelling the animation.
  17. # 2011.12.23 - Started Script and Finished.
  18. #
  19. #==============================================================================
  20. # �� Introduction
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # A missing feature from RPG Maker XP. Status effects had animations replaying
  23. # on them constantly to indicate that a user was affected by a state. Only the
  24. # state with the highest priority and possesses an animation will be played.
  25. #
  26. #==============================================================================
  27. # �� Instructions
  28. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  29. # To install this script, open up your script editor and copy/paste this script
  30. # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
  31. #
  32. # -----------------------------------------------------------------------------
  33. # State Notetags - These notetags go in the states notebox in the database.
  34. # -----------------------------------------------------------------------------
  35. #
  36. # Causes the status effect to play battle animation x repeatedly on the battler
  37. # if the battler is affected by this state and if this state is the highest
  38. # priority state with an animation.
  39. #
  40. #==============================================================================
  41. # �� Compatibility
  42. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  43. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  44. # it will run with RPG Maker VX without adjusting.
  45. #
  46. #==============================================================================

  47. module YEA
  48.   module STATE_ANIMATION
  49.    
  50.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  51.     # - Adjust the state animation settings here. -
  52.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  53.     # These settings decide whether or not state animations will cause the
  54.     # screen to flash, play sound effects, and what kinds of zoom levels will
  55.     # be used on actors affected by states with animations.
  56.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  57.     PLAY_SOUND = true      # 播放状态动画的声音?
  58.     PLAY_FLASH = false      # 使用屏幕闪光的状态动画?
  59.    
  60.     PLAY_ACTOR = false      # 在角色上播放动画?
  61.     ACTOR_ZOOM = 0.25       #0.25  角色动画缩放水平
  62.    
  63.   end # STATE_ANIMATION
  64. end # YEA

  65. #==============================================================================
  66. # �� Editting anything past this point may potentially result in causing
  67. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  68. # halitosis so edit at your own risk.
  69. #==============================================================================

  70. module YEA
  71.   module REGEXP
  72.   module STATE
  73.    
  74.     STATEANI = /<(?:STATE_ANIMATION|state ani|animation|ani):[ ](\d+)>/i
  75.    
  76.   end # STATE
  77.   end # REGEXP
  78. end # YEA

  79. #==============================================================================
  80. # �� DataManager
  81. #==============================================================================

  82. module DataManager
  83.   
  84.   #--------------------------------------------------------------------------
  85.   # alias method: load_database
  86.   #--------------------------------------------------------------------------
  87.   class <<self; alias load_database_sani load_database; end
  88.     def self.load_database
  89.       load_database_sani
  90.       load_notetags_sani
  91.     end
  92.   
  93.   #--------------------------------------------------------------------------
  94.   # new method: load_notetags_sani
  95.   #--------------------------------------------------------------------------
  96.   def self.load_notetags_sani
  97.     for state in $data_states
  98.       next if state.nil?
  99.       state.load_notetags_sani
  100.       end
  101.      end
  102.     end
  103.     # DataManager
  104.   
  105.   #--------------------------------------------------------------------------
  106.   # # �� RPG::State
  107.   #--------------------------------------------------------------------------
  108.   
  109.   class RPG::State < RPG::BaseItem
  110.    
  111.   #--------------------------------------------------------------------------
  112.   # public instance variables
  113.   #--------------------------------------------------------------------------
  114.   attr_accessor :state_animation
  115.   
  116.   def load_notetags_sani
  117.     @state_animation = 0
  118.     #---
  119.         self.note.split(/[\r\n]+/).each { |line|
  120.         case line
  121.         #---
  122.       
  123.         when YEA::REGEXP::STATE::STATEANI
  124.           @state_animation = $1.to_i
  125.         end
  126.         } # self.note.split
  127.         #---
  128.         
  129.       end
  130.       
  131.     end # RPG::State


  132. #==============================================================================
  133. #�� Sprite_Battler
  134. #==============================================================================

  135. class Sprite_Battler < Sprite_Base
  136.   
  137.   #--------------------------------------------------------------------------
  138.   # class variables
  139.   #--------------------------------------------------------------------------
  140.   @@state_ani_checker = []
  141.   @@state_ani_spr_checker = []
  142.   @@_reference_count = {}
  143.   
  144.   #--------------------------------------------------------------------------
  145.   # alias method: initialize
  146.   #--------------------------------------------------------------------------
  147.   alias sprite_battler_initialize_sani initialize
  148.   def initialize(viewport, battler = nil)
  149.     sprite_battler_initialize_sani(viewport, battler)
  150.     @state_ani_duration = 0
  151.   end
  152.   
  153.   #--------------------------------------------------------------------------
  154.   # alias method: dispose
  155.   #--------------------------------------------------------------------------
  156.   alias sprite_battler_dispose_sani dispose
  157.   def dispose
  158.     dispose_state_animation
  159.     sprite_battler_dispose_sani
  160.   end
  161. #==============================================================================
  162. #
  163. # alias method: setup_new_effect
  164. #==============================================================================
  165. alias sprite_battler_setup_new_effect_sani setup_new_effect
  166. def setup_new_effect
  167.   sprite_battler_setup_new_effect_sani
  168.   setup_state_ani_effect
  169. end

  170. #=====
  171. # new method: setup_state_ani_effect
  172. #=====
  173. def setup_state_ani_effect
  174.   return if @battler.state_animation_id.nil?
  175.   if @battler.state_animation_id == 0
  176.     dispose_state_animation
  177.   else
  178.     animation = $data_animations[@battler.state_animation_id]
  179.     start_state_animation(animation)
  180.     end
  181.   end
  182.   
  183.   #--------------------------------------------------------------------------
  184.   # alias method: update
  185.   #--------------------------
  186.    alias sprite_battler_update_sani update
  187.    def update
  188.      sprite_battler_update_sani
  189.      update_state_animations
  190.    end
  191.    
  192.    #=======
  193.    # new method: update_state_animations
  194.    #===============
  195.    def update_state_animations
  196.      update_state_animation
  197.      @@state_ani_checker.clear
  198.      @@state_ani_spr_checker.clear
  199.    end
  200.    
  201.    #---------------------
  202.    #new method: state_animation?
  203.    #----------------------
  204.    def state_animation?
  205.      return !@state_animation.nil?
  206.    end
  207.    
  208.    #------------------
  209.    # new method: start_state_animation
  210.    #---------------------
  211.    def start_state_animation(animation, mirror = true)
  212.      return if !@state_animation.nil? && @state_animation.id == animation.id
  213.      dispose_state_animation
  214.      @state_animation = animation
  215.      return if @state_animation.nil?
  216.      @state_ani_mirror = mirror
  217.      set_animation_rate
  218.      @state_ani_duration = @state_animation.frame_max * @ani_rate + 1
  219.      load_state_animation_bitmap
  220.      make_state_animation_sprites
  221.      set_state_animation_origin
  222.      end
  223.    
  224.   #---------------------------
  225. # new method: load_state_animation_bitmap
  226.    #------------------------
  227.    def load_state_animation_bitmap
  228.      animation1_name = @state_animation.animation1_name
  229.      animation1_hue = @state_animation.animation1_hue
  230.      animation2_name = @state_animation.animation2_name
  231.      animation2_hue = @state_animation.animation2_hue
  232.      @state_ani_bitmap1 = Cache.animation(animation1_name, animation1_hue)
  233.      @state_ani_bitmap2 = Cache.animation(animation2_name, animation2_hue)
  234.      if @@_reference_count.include?(@state_ani_bitmap1)
  235.        @@_reference_count[@state_ani_bitmap1] += 1
  236.      else
  237.        @@_reference_count[@state_ani_bitmap1] = 1
  238.      end
  239.      if @@_reference_count.include?(@ani_bitmap2)
  240.        @@_reference_count[@state_ani_bitmap2] += 1
  241.      else
  242.        @@_reference_count[@state_ani_bitmap2] = 1
  243.      end
  244.      Graphics.frame_reset
  245.      end
  246.    
  247. #-------------------  
  248. # new method: make_state_animation_sprites  
  249. #----------------------  
  250.    def make_state_animation_sprites
  251.      @state_ani_sprites = []
  252.      if @use_sprite && !@@state_ani_spr_checker.include?(@state_animation)
  253.        16.times do
  254.          sprite = ::Sprite.new(viewport)
  255.          sprite.visible = true
  256.          @state_ani_sprites.push(sprite)
  257.        end
  258.        if @state_animation.position == 3
  259.          @@state_ani_spr_checker.push(@animation)
  260.        end
  261.      end
  262.      @state_ani_duplicated = @@state_ani_checker.include?(@state_animation)
  263.      if !@state_ani_duplicated && @state_animation.position == 3
  264.        @@state_ani_checker.push(@state_animation)
  265.      end
  266.      end
  267.    
  268.    #-----------------
  269.    # new method: set_state_animation_origin
  270.    #-------------------
  271.   def set_state_animation_origin
  272.     if @state_animation.position == 3
  273.     if viewport == nil
  274.       @state_ani_ox = Graphics.width / 2
  275.       @state_ani_oy = Graphics.height / 2
  276.     else
  277.       @state_ani_ox = viewport.rect.width / 2
  278.       @state_ani_oy = viewport.rect.height / 2
  279.     end
  280.   else
  281.     @state_ani_ox = x - ox + width / 2
  282.     @state_ani_oy = y - oy + height / 2
  283.     if @state_animation.position == 0
  284.       @state_ani_oy -= height / 2
  285.     elsif @state_animation.position == 2
  286.       @state_ani_oy += height / 2
  287.     end
  288.   end
  289.   end
  290.    
  291.    #--------------
  292.    # new method: dispose_state_animation
  293.    #-------------
  294.    def dispose_state_animation
  295.      if @state_ani_bitmap1
  296.        @@_reference_count[@state_ani_bitmap1] -= 1
  297.        if @@_reference_count[@state_ani_bitmap1] == 0
  298.          @state_ani_bitmap1.dispose
  299.        end
  300.      end
  301.      if @state_ani_bitmap2
  302.        @@_reference_count[@state_ani_bitmap2] -= 1
  303.        if @@_reference_count[@state_ani_bitmap2] == 0
  304.          @state_ani_bitmap2.dispose
  305.        end
  306.      end
  307.      if @state_ani_sprites
  308.        @state_ani_sprites.each {|sprite| sprite.dispose }
  309.        @state_ani_sprites = nil
  310.        @state_animation = nil
  311.      end
  312.      @state_ani_bitmap1 = nil
  313.      @state_ani_bitmap2 = nil
  314.      end
  315.    
  316.    #--------------
  317.      # new method: update_state_animation
  318.    #--------------  
  319.    def update_state_animation
  320.      return unless state_animation?
  321.      @state_ani_duration -= 1
  322.      if @state_ani_duration % @ani_rate == 0
  323.        if @state_ani_duration > 0
  324.          @state_frame_index = @state_animation.frame_max
  325.          change = (@state_ani_duration + @ani_rate - 1) / @ani_rate
  326.          @state_frame_index -= change
  327.          @state_animation.timings.each do |timing|
  328.            next unless timing.frame == @state_frame_index
  329.            state_animation_process_timing(timing)
  330.          end
  331.        else
  332.          @state_ani_duration = @state_animation.frame_max * @ani_rate + 1
  333.        end
  334.      end
  335.      return if @state_frame_index.nil?
  336.      state_animation_set_sprites(@state_animation.frames[@state_frame_index])
  337.      set_state_animation_origin
  338.    end  
  339.    
  340.    #~~~~~~~~~~~~~~~~
  341.    # new method: end_state_animation
  342.    #~~~~~~~~~~~~~~~~
  343.    def end_state_animation
  344.      dispose_state_animation
  345.      end
  346.    
  347.      #~~~~~~~~~~~~
  348.    # new method: state_animation_set_sprites
  349.    #~~~~~~~~~~~~~~~~~~
  350.    def state_animation_set_sprites(frame)
  351.      return if @state_animation.nil?
  352.      return if frame.nil?
  353.      cell_data = frame.cell_data
  354.      @state_ani_sprites.each_with_index do |sprite, i|
  355.        next unless sprite
  356.        pattern = cell_data[i, 0]
  357.        if !pattern || pattern < 0
  358.          sprite.visible = true
  359.          next
  360.        end
  361.        sprite.bitmap = pattern < 100 ? @state_ani_bitmap1 : @state_ani_bitmap2
  362.        sprite.visible = true
  363.        sprite.src_rect.set(pattern % 5 * 192,
  364.        pattern % 100 / 5 * 192, 192, 192)
  365.        if @state_ani_mirror
  366.          sprite.x = @state_ani_ox - cell_data[i, 1]
  367.          sprite.y = @state_ani_oy + cell_data[i, 2]
  368.          sprite.angle = (360 - cell_data[i, 4])
  369.          sprite.mirror = (cell_data[i, 5] == 0)
  370.        else
  371.          sprite.x = @state_ani_ox + cell_data[i, 1]
  372.          sprite.y = @state_ani_oy + cell_data[i, 2]
  373.          sprite.angle = cell_data[i, 4]
  374.          sprite.mirror = (cell_data[i, 5] == 1)
  375.        end
  376.        sprite.z = self.z + 250 + i
  377.        sprite.ox = 96
  378.        sprite.oy = 96
  379.        sprite.zoom_x = cell_data[i, 3] / 100.0
  380.        sprite.zoom_y = cell_data[i, 3] / 100.0
  381.        if @battler.actor?
  382.          zoom = YEA::STATE_ANIMATION::ACTOR_ZOOM
  383.          sprite.zoom_x *= zoom
  384.          sprite.zoom_y *= zoom
  385.        end
  386.        sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  387.        sprite.blend_type = cell_data[i, 7]
  388.      end
  389.      end
  390.    
  391. #~~~~~~~~~~~~~~~~~~~~~~~~~~~   
  392. # new method: state_animation_process_timing   
  393. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
  394. def state_animation_process_timing(timing)
  395.    timing.se.play if YEA::STATE_ANIMATION::PLAY_SOUND
  396.    case timing.flash_scope
  397.    when 1
  398.      self.flash(timing.flash_color, timing.flash_duration * @ani_rate)
  399.      when 2
  400.        return unless YEA::STATE_ANIMATION::PLAY_FLASH
  401.        if viewport && !@state_ani_duplicated
  402.          flash_amount = timing.flash_duration * @ani_rate
  403.          viewport.flash(timing.flash_color, flash_amount)
  404.        end
  405.        when 3
  406.          self.flash(nil, timing.flash_duration * @ani_rate)
  407.        end
  408.      end
  409.      
  410.      end # Sprite_Battler  
  411.    
  412. # ~~~~~~~~~~  
  413. # �� Game_BattlerBase   
  414. # ~~~~~~~~~~  
  415.    
  416.   class Game_BattlerBase   
  417.    
  418. #  
  419. # public instance variables  
  420. #  
  421.    attr_accessor :state_animation_id
  422.    
  423. #  
  424.    # alias method: refresh
  425. #  
  426.    alias game_battlerbase_refresh_sani refresh
  427.    def refresh
  428.      game_battlerbase_refresh_sani
  429.      reload_state_animation
  430.      end  
  431.      
  432. #   
  433. # new method: reload_state_animation   
  434. #
  435. def reload_state_animation
  436.    @state_animation_id = 0
  437.    return if actor? && !YEA::STATE_ANIMATION::PLAY_ACTOR
  438.    for state in states
  439.      next unless state.state_animation > 0
  440.      @state_animation_id = state.state_animation
  441.      break
  442.    end
  443. end

  444. end # Game_BattlerBase


  445. #
  446. # �� End of File
  447. #
  448. #
  449. #
复制代码
[/pre]
梦石
0
星屑
50
在线时间
68 小时
注册时间
2011-11-12
回帖
76
发表于 2017-8-19 14:03:03 | 显示全部楼层
我只懂得.z是有关图层的
397 行     sprite.z = self.z + 250 + i
250改大一点试试??
已经在做游戏了~~~愉悦的做游戏体验
回复

使用道具 举报

梦石
0
星屑
60
在线时间
32 小时
注册时间
2009-3-19
回帖
6
 楼主| 发表于 2017-8-19 16:25:56 | 显示全部楼层
Nil2011 发表于 2017-8-19 14:03
我只懂得.z是有关图层的
397 行     sprite.z = self.z + 250 + i
250改大一点试试?? ...

谢谢 我先试一下!
回复

使用道具 举报

梦石
0
星屑
60
在线时间
32 小时
注册时间
2009-3-19
回帖
6
 楼主| 发表于 2017-8-19 16:36:55 | 显示全部楼层
mmmlqaz 发表于 2017-8-19 16:25
谢谢 我先试一下!

谢谢我找到问题解决方法了!
Sprite_Base
207行     sprite.z = self.z + 250 + i (250加到320就好了)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部