Window Part 1 v1.3Tutorial #1
Other past tutorials:
-RPGMaker XP Tutorial 1 For Noobs
http://www.crankeye.com/forums/viewtopic.php?p=55556#55556Windows and Scene's are the basis of your menus. When you use the title screen you see three commands. That is a
window. The interaction between moving between these three commands is
scene interaction.
WindowsWindows are very simple. RGSS has simplified this tremendously for us. A window is basically an area to put information. Not necessarily a block for text (but you can do this).
When you use a window and put text in it, you are not putting text in the window so to speak, you are actually putting text in the
Bitmap. Let's take a look at the superclasses of making a window.
The main Window class is Window_Base. I call it "Father Window" because all other windows follow it's rules. It contains:
-- current windowskin syntax
-- self disposing method
-- text color
-- actor's graphic
-- actor's name
-- actor's class
-- actor's level
-- actor's text for current state
-- actor's state
-- actor's exp
-- actor's hp
-- actor's sp
-- actor's parameters (Atk, Pdef, Mdef, Str, Dex, Agi, Int)
-- item's name syntax
This is the basic layout of Window_Base. Of course you can add more, but this is the basis.
Let's look at it even further and at the same time, learn a little about
methods and definitions.
class Window_Base < Window
This is very important. RGSS has defined a
class named Window_Base. But it has also made it use the contents of a
superclass of the class Window. Window is a hidden class for RGSS to interpret. If you want to know the contents of Window or any other hidden script please search for the RMXP Help File. It contains everything you need.
So in otherwords the class Window_Base is in a sense a "underclass" to the superclass Window.
def initialize(x, y, width, height)
super()
-- x # Horizontal Position of the Window
-- y #Vertical Position of the Window
-- width # Width of the Window
-- height # Height of the Window
X and Y may be positive or negative.
This is pretty important. This is the
method initialize with four
attributes. To create a window you need to have values to these four attributes. It also takes the superclasses' attributes as well.
So as you see in order to create any window you must have these four attributes. That's not to say they have to be a number. Leaving X and Y just X and Y will make these values 0.
In order to use these values for a window you must have a superclass. Guess what that superclass is? That's right. Window_Base
class Window_Blah < Window_Base
This is the syntax for creating your class for your window. But that's not all of it. You must also use the superclasses' attributes.
But that's just the window. The area you put your information in is the Bitmap (Another hidden script). Let me show you how to create a basic window.
class Window_Blah < Window_Base
def initialize
super(0,0, 599, 329)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(x,y,155,155,"This is some text",1)
end
end
We'll go through this step by step.
class Window_Blah < Window_Base
You created a new class Window_Blah with a superclass Window_Base.
def initialize
super(0,0, 599, 329)
This is important. This is the initialize method. It also gives values the the superclass's attributes. This is the window's size.
self.contents = Bitmap.new(width - 32, height - 32)
*****This is important as well. Probably the most. You will use this syntax everytime you create a new window. In order to call any class you must use a .new after the name of the class to call it. Don't ask why. I don't know.
self.contents
This is RGSS syntax. Self refers to itself. Contents is a hidden method. This is where you put the contents of the window. But in order to do this you need to fill this window up. Bitmap.new(width - 32, height - 32) is the syntax you use for creating the content section of your window. Then you can use other methods in Bitmap as well because the contents of your Window are the contents of the Bitmap class. ******
refresh
Refresh may seem like a local variable, but it isn't. If a local variable has no value it is treated as a method. Refresh is the method it will call in the initialize method.
end
Ends the initialize method.
def refresh
self.contents.clear
This creates the refresh method. It also clears all the contents of the window. This is a method in Bitmap. Convenient huh?
self.contents.draw_text(x,y,155,155,"This is some text",1)
end
end
Draw's text in the window. The attributes are (X, Y, Width, Height, Text, Alignment)
Alignment
0 = left align from width
1= center align
2 = right align from width
Ends the refresh method
and the class.
So here it is again.
class Window_Blah < Window_Base
def initialize
super(0,0, 599, 329)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(x,y,155,155,"This is some text",1)
end
end
To call this window create an event. Find the last command on the third tab and write:
Window_Blah.new
It won't dispose whenever you go to your menu because it's not in a scene. That is later in Tutorial 2.
So what have we learned?
We have learned how to create a window and the attributes of a window. We have learned about superclasses and methods.
Long and simple but if you take the time to read this you will understand completely.
Any questions please post them.
~Constance