本帖最后由 guoxiaomi 于 2019-12-26 21:00 编辑
先说明为什么选择在伤害数字的时候进行震动:
1. 你给的示例代码就是显示伤害数字的部分,注意变量:@_damage_duration。“彩虹神剑”脚本重新排列了动画的顺序,会同时播放使用者、对象方动画和伤害数字,并且分多次显示伤害。所以彩虹神剑选择在显示伤害数字的时候震动角色。
2. 对于默认脚本,由于动画中击中目标的那一帧通常不固定,所以做起来比较麻烦,需要对不同的动画使用不同的设定。而伤害显示是一个固定的流程,所以如果只是举一个简单的例子,不如就放在显示伤害数字的地方。
如果想要在播放动画的时候就震动,击中的那一帧必须单独配置好,最简单的方案其实修改方法animation_process_timing:
def animation_process_timing(timing, hit) if (timing.condition == 0) or (timing.condition == 1 and hit == true) or (timing.condition == 2 and hit == false) if timing.se.name != "" se = timing.se Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch) end case timing.flash_scope when 1 self.flash(timing.flash_color, timing.flash_duration * 2) when 2 if self.viewport != nil self.viewport.flash(timing.flash_color, timing.flash_duration * 2) end when 3 self.flash(nil, timing.flash_duration * 2) end end end
def animation_process_timing(timing, hit)
if (timing.condition == 0) or
(timing.condition == 1 and hit == true) or
(timing.condition == 2 and hit == false)
if timing.se.name != ""
se = timing.se
Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
end
case timing.flash_scope
when 1
self.flash(timing.flash_color, timing.flash_duration * 2)
when 2
if self.viewport != nil
self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
end
when 3
self.flash(nil, timing.flash_duration * 2)
end
end
end
添加一个特殊的se,当读到这个se的名称时,角色需要进行震动就可以了。
Project1.zip
(200.66 KB, 下载次数: 53)
代码如下,注意范例里面动画7的设置以及添加的空文件shake.ogg:
class Sprite_Battler < RPG::Sprite alias _old_animation_process_timing animation_process_timing def animation_process_timing(timing, hit) if timing.se.name == "shake" if hit c = timing.flash_color self.ox += c.red - c.green self.oy += c.blue - c.alpha end else _old_animation_process_timing(timing, hit) end end end
class Sprite_Battler < RPG::Sprite
alias _old_animation_process_timing animation_process_timing
def animation_process_timing(timing, hit)
if timing.se.name == "shake"
if hit
c = timing.flash_color
self.ox += c.red - c.green
self.oy += c.blue - c.alpha
end
else
_old_animation_process_timing(timing, hit)
end
end
end
|