This is a resource which I hope to develope to the point it is used... A lot. (wishful thinking)
At the moment what it does is allow you to create scenes, while only having to initialize the objects in the scene and writing the seperate update methods. (for interaction)
Don't forget to make the scene a sub-class of Scene_Base, ie - (class Scene_Name < Scene_Base)
In the future I hope to include introduction animation methods and closing animation methods, as well as a variety of other methods to make writing scenes easier.
The only real difference, is that when you create an object in a scene, instead of doing -
@playtime_window = Window_PlayTime.new
You'd do -
@objects['time'] = Window_PlayTime.new
And when refering to the object, you'd obviously use -
@objects['time']
as opposed to the prior.
You can also play music in the scene, simply by adding -
super('Song Name Here')
Into the scenes initialize method.
Example -
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
# This class performs menu screen processing.
#==============================================================================
class Scene_Menu < Scene_Base
#--------------------------------------------------------------------------
# * Object Initialization
# menu_index : command cursor's initial position
#--------------------------------------------------------------------------
def initialize(menu_index = 0)
@menu_index = menu_index
super('015-Theme04')
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make command window
s1 = $data_system.words.item
s2 = $data_system.words.skill
s3 = $data_system.words.equip
s4 = "Status"
s5 = "Save"
s6 = "End Game"
@objects['command'] = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
@objects['command'].index = @menu_index
# If number of party members is 0
if $game_party.actors.size == 0
# Disable items, skills, equipment, and status
@objects['command'].disable_item(0)
@objects['command'].disable_item(1)
@objects['command'].disable_item(2)
@objects['command'].disable_item(3)
end
# If save is forbidden
if $game_system.save_disabled
# Disable save
@objects['command'].disable_item(4)
end
# Make play time window
@objects['time'] = Window_PlayTime.new
@objects['time'].x = 0
@objects['time'].y = 224
# Make steps window
@objects['steps'] = Window_Steps.new
@objects['steps'].x = 0
@objects['steps'].y = 320
# Make gold window
@objects['gold'] = Window_Gold.new
@objects['gold'].x = 0
@objects['gold'].y = 416
# Make status window
@objects['status'] = Window_MenuStatus.new
@objects['status'].x = 160
@objects['status'].y = 0
super
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If command window is active: call update_command
if @objects['command'].active
update_command
return
end
# If status window is active: call update_status
if @objects['status'].active
update_status
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If command other than save or end game, and party members = 0
if $game_party.actors.size == 0 and @command_window.index < 4
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Branch by command window cursor position
case @objects['command'].index
when 0 # item
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to item screen
$scene = Scene_Item.new
when 1 # skill
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@objects['command'].active = false
@objects['status'].active = true
@objects['status'].index = 0
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@objects['command'].active = false
@objects['status'].active = true
@objects['status'].index = 0
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@objects['command'].active = false
@objects['status'].active = true
@objects['status'].index = 0
when 4 # save
# If saving is forbidden
if $game_system.save_disabled
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to save screen
$scene = Scene_Save.new
when 5 # end game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to end game screen
$scene = Scene_End.new
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when status window is active)
#--------------------------------------------------------------------------
def update_status
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Make command window active
@objects['command'].active = true
@objects['status'].active = false
@objects['status'].index = -1
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @objects['command'].index
when 1 # skill
# If this actor's action limit is 2 or more
if $game_party.actors[@objects['status'].index].restriction >= 2
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to skill screen
$scene = Scene_Skill.new(@objects['status'].index)
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to equipment screen
$scene = Scene_Equip.new(@objects['status'].index)
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to status screen
$scene = Scene_Status.new(@objects['status'].index)
end
return
end
end
end
C & C please.
Script -
class Scene_Base
def initialize(bgm = nil)
# Create Objects Hash
@objects = {}
# Store bgm value
@bgm = bgm
end
def main
# Start playing bgm unless one is not provided
$game_system.bgm_play(RPG::AudioFile.new(@bgm)) unless @bgm.nil?
# Execute transition
Graphics.transition
# Main loop
loop do
# Update Scene
update
# Abort loop if screen is changed
break if $scene != self
end
# Prepare for transition
Graphics.freeze
# Dispose of Scene
dispose
end
def update
# Update Objects unless none exist
unless @objects.empty?
for key in @objects.keys
@objects[key].update
end
end
# Update Graphics
Graphics.update
# Update input information
Input.update
end
def dispose
# Dispose of Objects unless none exist
unless @objects.empty?
for key in @objects.keys
@objects[key].dispose
end
end
# Stop playing bgm unless one is not playing
$game_system.bgm_stop unless @bgm.nil?
end
end