#==============================================================================
# ** Scene_Splash
#------------------------------------------------------------------------------
# This class performs the splash screen processing.
#==============================================================================
class Scene_Splash < Scene_Base
#--------------------------------------------------------------------------
# * Constant Variables
#--------------------------------------------------------------------------
Splash_Image_Prefix = 'Splash' # Splash Images begin with what string
Splash_Dir = 'Graphics/Pictures/' # Directory where the splash images are
Seconds_Per_Splash = 3 # Number of seconds to spend per splash
FadeIn_Seconds = 1 # Number of seconds to fade in a splash
FadeOut_Seconds = 1 # Number of seconds to fade out a splash
Window_Width = 544 # Pixel width of the window.
Window_Height = 416 # Pixel height of the window.
Allow_Skip = true # Allow Splashes to be skipped via input
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
# The current index we are at in our splash array.
@splash_index = 0
@cycle = 0
@timer = 0
# Figure out the time in terms of frames.
@frames_per_fadein = FadeIn_Seconds * Graphics.frame_rate
@frames_per_screen = Seconds_Per_Splash * Graphics.frame_rate
@frames_per_fadeout = FadeOut_Seconds * Graphics.frame_rate
# Gather the names of the images that will be the splash screens.
@splash_screens = Dir[Splash_Dir + Splash_Image_Prefix + '*.*']
for i in 0...@splash_screens.size
@splash_screens[i] = @splash_screens[i].split('/').last.split('.')[0]
end
@splash_screens.sort!
$scene = Scene_Title.new if @splash_screens.empty?
# Create our sprite.
@splash_sprite = Sprite.new
@splash_sprite.bitmap = Bitmap.new(Window_Width, Window_Height)
@splash_sprite.opacity = 0
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
return if @splash_screens.empty?
# If the image needs to be drawn.
if @old_splash_index != @splash_index && !@splash_screens.empty?
@old_splash_index = @splash_index
begin
RPG::BGM.new(@splash_screens[@splash_index], 100, 100).play
rescue
end
splash = Bitmap.new(Splash_Dir + @splash_screens[@splash_index])
rect_x = (Window_Width >> 1) - (splash.width >> 1)
rect_y = (Window_Height >> 1) - (splash.height >> 1)
draw_x = [rect_x, 0].max
draw_y = [rect_y, 0].max
splash_rect = Rect.new(0, 0, splash.width, splash.height)
@splash_sprite.bitmap.clear
@splash_sprite.bitmap.blt(draw_x, draw_y, splash, splash_rect)
end
@timer += 1
case @cycle
when 0
@splash_sprite.opacity += (255 / @frames_per_fadein)
if @timer > @frames_per_fadein
@timer = 0
@cycle = 1
end
when 1
if @timer > @frames_per_screen
@timer = 0
@cycle = 2
Audio.bgm_fade(FadeOut_Seconds * 1000)
end
when 2
@splash_sprite.opacity -= (255 / @frames_per_fadein)
if @timer > @frames_per_fadeout
@timer = 0
@cycle = 0
@splash_index += 1
end
end
$scene = Scene_Title.new if @splash_index == @splash_screens.size
$scene = Scene_Title.new if Input.trigger?(Input::B) && Allow_Skip
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
@splash_sprite.bitmap.dispose unless @splash_sprite.bitmap.disposed?
@splash_sprite.dispose unless @splash_sprite.disposed?
RPG::BGM.stop
end
end