The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Tutorials and Eventing => Topic started by: Tsunokiette on November 01, 2006, 12:05:11 AM

Title: How to Set up a Multi-Scene Scene
Post by: Tsunokiette on November 01, 2006, 12:05:11 AM
Many people think it's complicated to write scenes such as scene_menu while including all of the scenes together in a single scene, and still keep it relatively lag free. It's not as hard as you would think. First, just have variables automaticly set to false, they turn true after you've introduced the scene. EX: Moved windows or changed visability ect.

And, like Scene_Battle, use an instance variable (scene as opposed to phase) to keep track of what scene you're on.

Here's an example template for creating a Scene_Menu -

class Scene_Menu

def initialize
@main = false
@items = false
@status = false
@spells = false
@equip = false
@file = false
@close = false
@scene = 0
end

def main
Graphics.transition
loop do
basic_update
update
break if not_scene
end
Graphics.freeze
dispose
end

def basic_update
Graphics.update
Input.update
end

def update
case @scene
when 0
update_main
when 1
update_items
when 2
update_status
when 3
update_spells
when 4
update_equip
when 5
update_file
when 6
update_close
end
end

def not_scene
return $scene != self
end

def dispose
self.instance_variables.each.do(|item|
if item.is_a?(Window) or item.is_a?(Sprite)
item.dispose
end)
end

def update_main
main_init if !@main
else
# Update main scene
end
end

def update_items
items_init if !@items
else
# Update item scene
end
end

def update_status
status_init if !@status
else
# Update status scene
end
end

def update_spells
spells_init if !@spells
else

end
end

def update_equip
equip_init if !@equip
else

end
end

def update_file
file_init if !@file
else

end
end

def update_close
close_init if !@close
else

end
end

def main_init
# Set up Scene for Main Scene
@main = true
end

def items_init
# Set up Scene for Items Scene
@items = true
end

def status_init
# Set up Scene for Status Scene
@status = true
end

def spells_init
# Set up Scene for Spells Scene
@spells = true
end

def equip_init
# Set up Scene for Equip Scene
@equip = true
end

def file_init
# Set up Scene for File Scene
@file = true
end

def close_init
# Set up Scene for Close Scene
@close = true
end

end


I'll explain the rest later, G2G.
Title: Re: How to Set up a Multi-Scene Scene
Post by: Blizzard on November 01, 2006, 12:18:23 AM
Nice start. I always checked if the windows are nil and if not, I checked if they are active. That's how I did it.
Title: Re: How to Set up a Multi-Scene Scene
Post by: Tsunokiette on November 01, 2006, 02:14:49 AM
Thanks ^_^ .

How it Works

What it does is loop and run a basic update (Grahpics and Input) then it runs the update method.
The update method is the most important part of the idea, it checks what scene you are running and runs the particular update method for that scene.
You'll notice that there are variables set to false in the begining. You will also (in the branched update methods) see something along the lines of -

main_init if !@main
else

end


By putting if !@main, we are checking to see if @main equals false. What it will then run is the preceding method - main_init.

This is what the variables are for, to make sure the scene is initialized properly, and that it doesn't happen more than once.

All you have to do is create all of the windows before the main loop, and update each scene like you normaly would in their respective update method.

This should stay pretty lag free considering it will only run each scene if it's active.

To change the scene, you use -

@scene = A_NUMBER

The number reflects what scene it is. For example, in the given template the main scene (ie: the menu itself) is given the number 0.

This will work unless you for some reason dispose windows inside the scene itself.
Title: Re: How to Set up a Multi-Scene Scene
Post by: Nightwolf on November 01, 2006, 09:26:02 AM
Good...very good!