设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3503|回复: 6
打印 上一主题 下一主题

[原创发布] 同时显示多个动画(可以重叠) 2.17更新

[复制链接]

Lv1.梦旅人

薄凉看客

梦石
0
星屑
50
在线时间
1269 小时
注册时间
2010-6-20
帖子
1316
跳转到指定楼层
1
发表于 2015-2-17 18:54:55 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 恐惧剑刃 于 2015-2-18 09:34 编辑


截图


工程截图

事件截图(第二张图有点问题,不过影响不大。)


地图效果,多动画(可以重叠)

地图效果,"全屏动画只显示一次"


战斗(附加了状态)


使用还原后



脚本



基础

RUBY 代码复制
  1. class RPG::Sprite < ::Sprite
  2.   def initialize(viewport = nil)
  3.     super(viewport)
  4.     @_whiten_duration = 0
  5.     @_appear_duration = 0
  6.     @_escape_duration = 0
  7.     @_collapse_duration = 0
  8.     @_damage_duration = 0
  9.     #@_animation_duration = 0
  10.     @_blink = false
  11.     @_animation = []
  12.     @_animation_hit = []
  13.     @_animation_duration = []
  14.     @_animation_sprites = []
  15.     @_loop_animation = []
  16.     @_loop_animation_sprites = []
  17.     @_loop_animation_index = []
  18.   end
  19.   def animation(animation, hit)
  20.     #dispose_animation
  21.     return if animation == nil
  22.     @_animation << animation
  23.     @_animation_hit << hit
  24.     @_animation_duration << animation.frame_max
  25.     animation_name = animation.animation_name
  26.     animation_hue = animation.animation_hue
  27.     bitmap = RPG::Cache.animation(animation_name, animation_hue)
  28.     if @@_reference_count.include?(bitmap)
  29.       @@_reference_count[bitmap] += 1
  30.     else
  31.       @@_reference_count[bitmap] = 1
  32.     end
  33.     _animation_sprites = []
  34.     if animation.position != 3 or not @@_animations.include?(animation)
  35.       for i in 0..15
  36.         sprite = ::Sprite.new(self.viewport)
  37.         sprite.bitmap = bitmap
  38.         sprite.visible = false
  39.         _animation_sprites.push(sprite)
  40.       end
  41.       @_animation_sprites << _animation_sprites
  42.       unless @@_animations.include?(animation)
  43.         @@_animations.push(animation)
  44.       end
  45.     end
  46.     update_animation
  47.   end
  48.   def loop_animation(animation)
  49.     return if animation == nil or @_loop_animation.include?(animation)
  50.     @_loop_animation << animation
  51.     @_loop_animation_index << 0
  52.     animation_name = animation.animation_name
  53.     animation_hue = animation.animation_hue
  54.     bitmap = RPG::Cache.animation(animation_name, animation_hue)
  55.     if @@_reference_count.include?(bitmap)
  56.       @@_reference_count[bitmap] += 1
  57.     else
  58.       @@_reference_count[bitmap] = 1
  59.     end
  60.     _loop_animation_sprites = []
  61.     for i in 0..15
  62.       sprite = ::Sprite.new(self.viewport)
  63.       sprite.bitmap = bitmap
  64.       sprite.visible = false
  65.       _loop_animation_sprites.push(sprite)
  66.     end
  67.     @_loop_animation_sprites << _loop_animation_sprites
  68.     update_loop_animation
  69.   end
  70.   def dispose_animation(v=nil)
  71.     for i in [email]0...@_animation_sprites.size[/email]
  72.       sprite = @_animation_sprites[i][0]
  73.       if sprite != nil
  74.         @@_reference_count[sprite.bitmap] -= 1
  75.         if @@_reference_count[sprite.bitmap] == 0
  76.           sprite.bitmap.dispose
  77.         end
  78.       end
  79.       for sprite in @_animation_sprites[i]
  80.         sprite.dispose
  81.       end
  82.       @_animation_sprites[i].clear
  83.       #@_animation_sprites.delete_at(i)
  84.       #@_animation.delete_at(i)
  85.       #@_animation_hit.delete_at(i)
  86.       #@_animation_duration.delete_at(i)
  87.     end
  88.     @_animation_sprites.clear
  89.     @_animation.clear
  90.     @_animation_hit.clear
  91.     @_animation_duration.clear
  92.     if v.nil?
  93.       @_animation_sprites = nil
  94.       @_animation = nil
  95.       @_animation_hit = nil
  96.       @_animation_duration = nil
  97.     end
  98.   end
  99.   def dispose_loop_animation(v=nil)
  100.     for i in [email]0...@_loop_animation_sprites.size[/email]
  101.       sprite = @_loop_animation_sprites[i][0]
  102.       if sprite != nil
  103.         @@_reference_count[sprite.bitmap] -= 1
  104.         if @@_reference_count[sprite.bitmap] == 0
  105.           sprite.bitmap.dispose
  106.         end
  107.       end
  108.       for sprite in @_loop_animation_sprites[i]
  109.         sprite.dispose
  110.       end
  111.       @_loop_animation_sprites[i].clear
  112.       #@_loop_animation_sprites.delete_at(i)
  113.       #@_loop_animation.delete_at(i)
  114.       #@_loop_animation_index.delete_at(i)
  115.     end
  116.     @_loop_animation_sprites.clear
  117.     @_loop_animation.clear
  118.     @_loop_animation_index.clear
  119.     if v.nil?
  120.       @_loop_animation = nil
  121.       @_loop_animation_sprites = nil
  122.       @_loop_animation_index = nil
  123.     end
  124.   end
  125.   def effect?
  126.     @_whiten_duration > 0 or
  127.     @_appear_duration > 0 or
  128.     @_escape_duration > 0 or
  129.     @_collapse_duration > 0 or
  130.     @_damage_duration > 0 or
  131.     @_animation_duration.size > 0
  132.   end
  133.   def update
  134.     super
  135.     if @_whiten_duration > 0
  136.       @_whiten_duration -= 1
  137.       self.color.alpha = 128 - (16 - @_whiten_duration) * 10
  138.     end
  139.     if @_appear_duration > 0
  140.       @_appear_duration -= 1
  141.       self.opacity = (16 - @_appear_duration) * 16
  142.     end
  143.     if @_escape_duration > 0
  144.       @_escape_duration -= 1
  145.       self.opacity = 256 - (32 - @_escape_duration) * 10
  146.     end
  147.     if @_collapse_duration > 0
  148.       @_collapse_duration -= 1
  149.       self.opacity = 256 - (48 - @_collapse_duration) * 6
  150.     end
  151.     if @_damage_duration > 0
  152.       @_damage_duration -= 1
  153.       case @_damage_duration
  154.       when 38..39
  155.         @_damage_sprite.y -= 4
  156.       when 36..37
  157.         @_damage_sprite.y -= 2
  158.       when 34..35
  159.         @_damage_sprite.y += 2
  160.       when 28..33
  161.         @_damage_sprite.y += 4
  162.       end
  163.       @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
  164.       if @_damage_duration == 0
  165.         dispose_damage
  166.       end
  167.     end
  168.     if @_animation.size > 0 and (Graphics.frame_count % 2 == 0)
  169.       for i in [email]0...@_animation_duration.size[/email]
  170.         @_animation_duration[i] -= 1
  171.       end
  172.       update_animation
  173.     end
  174.     if @_loop_animation.size > 0 and (Graphics.frame_count % 2 == 0)
  175.       update_loop_animation
  176.       for i in [email]0...@_loop_animation_index.size[/email]
  177.         @_loop_animation_index[i] += 1
  178.         @_loop_animation_index[i] %= @_loop_animation[i].frame_max
  179.       end
  180.     end
  181.     if @_blink
  182.       @_blink_count = (@_blink_count + 1) % 32
  183.       if @_blink_count < 16
  184.         alpha = (16 - @_blink_count) * 6
  185.       else
  186.         alpha = (@_blink_count - 16) * 6
  187.       end
  188.       self.color.set(255, 255, 255, alpha)
  189.     end
  190.     @@_animations.clear
  191.   end
  192.   def update_animation
  193.     for i in [email]0...@_animation_duration.size[/email]
  194.       if @_animation_duration[i] <= 0
  195.         @_animation_duration[i] = nil
  196.         sprite = @_animation_sprites[i][0]
  197.         if sprite != nil
  198.           @@_reference_count[sprite.bitmap] -= 1
  199.           if @@_reference_count[sprite.bitmap] == 0
  200.             sprite.bitmap.dispose
  201.           end
  202.         end
  203.         for sprite in @_animation_sprites[i]
  204.           sprite.dispose
  205.         end
  206.         @_animation_duration.delete_at(i)
  207.         @_animation_sprites.delete_at(i)
  208.         @_animation.delete_at(i)
  209.         return
  210.       end
  211.       frame_index = @_animation[i].frame_max - @_animation_duration[i]
  212.       cell_data = @_animation[i].frames[frame_index].cell_data
  213.       position = @_animation[i].position
  214.       animation_set_sprites(@_animation_sprites[i], cell_data, position)
  215.       for timing in @_animation[i].timings
  216.         if timing.frame == frame_index
  217.           animation_process_timing(timing, @_animation_hit)
  218.         end
  219.       end
  220.     #else
  221.     #  dispose_animation
  222.     end
  223.   end
  224.   def update_loop_animation
  225.     for i in [email]0...@_loop_animation_index.size[/email]
  226.       frame_index = @_loop_animation_index[i]
  227.       cell_data = @_loop_animation[i].frames[frame_index].cell_data
  228.       position = @_loop_animation[i].position
  229.       animation_set_sprites(@_loop_animation_sprites[i], cell_data, position)
  230.       for timing in @_loop_animation[i].timings
  231.         if timing.frame == frame_index
  232.           animation_process_timing(timing, true)
  233.         end
  234.       end
  235.     end
  236.   end
  237.   def x=(x)
  238.     sx = x - self.x
  239.     if sx != 0
  240.       for each_sprites in [email]0...@_animation_sprites.size[/email]
  241.         for i in 0..15
  242.           @_animation_sprites[each_sprites][i].x += sx
  243.         end
  244.       end
  245.       for each_sprites in [email]0...@_loop_animation_sprites.size[/email]
  246.         for i in 0..15
  247.           @_loop_animation_sprites[each_sprites][i].x += sx
  248.         end
  249.       end
  250.     end
  251.     super
  252.   end
  253.   def y=(y)
  254.     sy = y - self.y
  255.     if sy != 0
  256.       for each_sprites in [email]0...@_animation_sprites.size[/email]
  257.         for i in 0..15
  258.           @_animation_sprites[each_sprites][i].y += sy
  259.         end
  260.       end
  261.       for each_sprites in [email]0...@_loop_animation_sprites.size[/email]
  262.         for i in 0..15
  263.           @_loop_animation_sprites[each_sprites][i].y += sy
  264.         end
  265.       end
  266.     end
  267.     super
  268.   end
  269. end


附件

RUBY 代码复制
  1. #==============================================================================
  2. # 应用多动画效果(事件)
  3. #==============================================================================
  4.  
  5. #==============================================================================
  6. # Scene_Map
  7. #==============================================================================
  8. class Scene_Map
  9.   # 刷新活动块
  10.   def spriteset_update
  11.     @spriteset.update
  12.   end
  13. end
  14. #==============================================================================
  15. # Interpreter
  16. #==============================================================================
  17. class Interpreter
  18.   alias animation_command_207 command_207
  19.   # 刷新活动块
  20.   def command_207
  21.     animation_command_207
  22.     $scene.spriteset_update
  23.     return true
  24.   end
  25. end
  26.  
  27. #==============================================================================
  28. # 应用多动画效果(战斗)
  29. #==============================================================================
  30.  
  31. =begin
  32.  
  33. 还有一小段代码,不便直接贴出,清自行修改!
  34. 找到 Sprite_Battler
  35. 默认 60 行 左右,替换为
  36.     # 动画 ID 与当前的情况有差异的情况下======================================
  37.     if @battler.damage == nil and @battler.ani_update
  38.       dispose_loop_animation(true)
  39.       @battler.ani_update = false
  40.       for i in [email][email protected]_animation_id.size[/email]
  41.         loop_animation($data_animations[@battler.state_animation_id[i]])
  42.       end
  43.     end#======================================================================
  44.  
  45.  
  46. =end
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. #==============================================================================
  54. # Game_Battler
  55. #==============================================================================
  56. class Game_Battler
  57.   def state_animation_id
  58.     id = []
  59.     for i in [email]0...@states.size[/email]
  60.       id[i] = $data_states[@states[i]].animation_id
  61.     end
  62.     return id
  63.   end
  64.   alias ani_add_state add_state
  65.   def add_state(*args)
  66.     ani_add_state(*args)
  67.     @ani_update = true
  68.   end
  69.   alias ani_remove_state remove_state
  70.   def remove_state(*args)
  71.     ani_remove_state(*args)
  72.     @ani_update = true
  73.   end
  74.   attr_accessor :ani_update
  75. end




详见工程


多动画.zip (204.56 KB, 下载次数: 237)

评分

参与人数 6星屑 +590 +1 收起 理由
龙夫三拳tan + 1 精品文章
zhouzhuofan1 + 20 比很久以前的多动画显示脚本要好.
RyanBern + 200 以后提问区有动画的问题果断摔链接.
邪月长啸 + 45 支持恋大
紫英晓狼1130 + 240 精品文章
·雾逝者· + 85 精品文章

查看全部评分

Lv4.逐梦者

梦石
0
星屑
7921
在线时间
1049 小时
注册时间
2012-4-3
帖子
1271

开拓者

2
发表于 2015-2-18 03:02:04 手机端发表。 | 只看该作者
这是一个令人期待的技术,我会继续关注你的。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
211
在线时间
845 小时
注册时间
2014-5-5
帖子
944
3
发表于 2015-2-18 19:03:14 | 只看该作者
已收藏~恋大的东西都很有意思
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
274 小时
注册时间
2014-2-22
帖子
335
4
发表于 2015-11-6 03:34:54 | 只看该作者
BUG:并行处理的话如果播放动画就会直接报错【估计自动执行也会一样?未测试

点评

TIP:报错的那一行改为 $scene.spriteset_update if $scene.is_a?(Scene_Map)  发表于 2021-1-12 17:07
啊...果然丢失了部分效果,还得修  发表于 2015-11-6 03:38
将$scene.spriteset_update注释掉似乎就可以解决问题了  发表于 2015-11-6 03:37
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-28 02:57

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表