Project1
标题: 请教如何在场景里使用闪烁的效果? [打印本页]
作者: 文雅夕露 时间: 2019-6-14 22:20
标题: 请教如何在场景里使用闪烁的效果?
VX并没有$game_screen.start_flash这个方法。
取代的是$game_map.screen.start_flash。
但这个方法只能在地图场景里使用。
不能在其他菜单场景里使用。
请问该怎么修改才能在菜单场景里使用闪烁功能?
作者: KB.Driver 时间: 2019-6-15 16:13
module Screen
class << self
attr_accessor :sprite
end
def self.start_flash(color, duration)
@sprite = Sprite.new
@sprite.z = 999
@sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
@sprite.bitmap.fill_rect(@sprite.bitmap.rect, color)
class << @sprite
attr_writer :duration
def update_opacity
@time ||= 0
self.opacity = (self.opacity * (@duration - @time - 1)) / (@duration - @time)
@time += 1
end
def showed?
@time == @duration - 1 || self.opacity == 0
end
end
@sprite.duration = duration
end
end
class << Graphics
alias update_for_screen_flash update
def update
update_for_screen_flash
if (sprite = Screen.sprite)
sprite.update_opacity
Screen.sprite = nil if sprite.showed?
end
end
end
module Screen
class << self
attr_accessor :sprite
end
def self.start_flash(color, duration)
@sprite = Sprite.new
@sprite.z = 999
@sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
@sprite.bitmap.fill_rect(@sprite.bitmap.rect, color)
class << @sprite
attr_writer :duration
def update_opacity
@time ||= 0
self.opacity = (self.opacity * (@duration - @time - 1)) / (@duration - @time)
@time += 1
end
def showed?
@time == @duration - 1 || self.opacity == 0
end
end
@sprite.duration = duration
end
end
class << Graphics
alias update_for_screen_flash update
def update
update_for_screen_flash
if (sprite = Screen.sprite)
sprite.update_opacity
Screen.sprite = nil if sprite.showed?
end
end
end
比较简单粗暴的实现方式
要使用时用Screen.start_flash(color, duration)
一个使用范例:
class Scene_Menu
alias start_for_screen start
def start
start_for_screen
Screen.start_flash(Color.new(255,0,0), 60)
end
end
class Scene_Menu
alias start_for_screen start
def start
start_for_screen
Screen.start_flash(Color.new(255,0,0), 60)
end
end
效果:
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |