Project1

标题: 请教如何在场景里使用闪烁的效果? [打印本页]

作者: 文雅夕露    时间: 2019-6-14 22:20
标题: 请教如何在场景里使用闪烁的效果?
VX并没有$game_screen.start_flash这个方法。
取代的是$game_map.screen.start_flash。
但这个方法只能在地图场景里使用。
不能在其他菜单场景里使用。
请问该怎么修改才能在菜单场景里使用闪烁功能?
作者: KB.Driver    时间: 2019-6-15 16:13
RUBY 代码复制
  1. module Screen
  2.   class << self
  3.     attr_accessor :sprite
  4.   end
  5.   def self.start_flash(color, duration)
  6.     @sprite = Sprite.new
  7.     @sprite.z = 999
  8.     @sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  9.     @sprite.bitmap.fill_rect(@sprite.bitmap.rect, color)
  10.     class << @sprite
  11.       attr_writer :duration
  12.  
  13.       def update_opacity
  14.         @time ||= 0
  15.         self.opacity = (self.opacity * (@duration - @time - 1)) / (@duration - @time)
  16.         @time += 1
  17.       end
  18.  
  19.       def showed?
  20.         @time == @duration - 1 || self.opacity == 0
  21.       end
  22.     end
  23.     @sprite.duration = duration
  24.   end
  25. end
  26.  
  27. class << Graphics
  28.   alias update_for_screen_flash update
  29.   def update
  30.     update_for_screen_flash
  31.     if (sprite = Screen.sprite)
  32.       sprite.update_opacity
  33.       Screen.sprite = nil if sprite.showed?
  34.     end
  35.   end
  36. end


比较简单粗暴的实现方式
要使用时用Screen.start_flash(color, duration)

一个使用范例:
RUBY 代码复制
  1. class Scene_Menu
  2.   alias start_for_screen start
  3.   def start
  4.     start_for_screen
  5.     Screen.start_flash(Color.new(255,0,0), 60)
  6.   end
  7. end


效果:







欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1