class Game_Player < Game_Character attr_reader :shake_mode attr_reader :shake_index attr_accessor :shake_time def set_shake(mode, index, time) @shake_mode = mode @shake_index = index @shake_time = time end def shake? return false unless @shake_time return @shake_time > 0 end end class Sprite_Character < Sprite_Base alias :reisen_shake_update :update def update reisen_shake_update update_reisen_shake end def update_reisen_shake return unless @character.is_a?(Game_Player) return unless @character.shake? indexs = rand(@character.shake_index) * (-1)^(rand(1) + 1) self.x += indexs if [0, 2].include?(@character.shake_mode) self.y += indexs if [1, 2].include?(@character.shake_mode) @character.shake_time -= 1 end end
class Game_Player < Game_Character
attr_reader :shake_mode
attr_reader :shake_index
attr_accessor :shake_time
def set_shake(mode, index, time)
@shake_mode = mode
@shake_index = index
@shake_time = time
end
def shake?
return false unless @shake_time
return @shake_time > 0
end
end
class Sprite_Character < Sprite_Base
alias :reisen_shake_update :update
def update
reisen_shake_update
update_reisen_shake
end
def update_reisen_shake
return unless @character.is_a?(Game_Player)
return unless @character.shake?
indexs = rand(@character.shake_index) * (-1)^(rand(1) + 1)
self.x += indexs if [0, 2].include?(@character.shake_mode)
self.y += indexs if [1, 2].include?(@character.shake_mode)
@character.shake_time -= 1
end
end
使用方法: 任意事件 -> 脚本 -> $game_player.set_shake(模式, 偏移, 时间)
其中:
模式 为一下数值: 0 水平方向震动; 1 竖直方向震动; 2, 0 和 1 的结合体
偏移 震动的像素值
时间 震动持续时间, 单位 帧 |