RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Constance's Window's Tutorial Part 1/2

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 89
Window Part 1 v1.3

Tutorial #1

Other past tutorials:

-RPGMaker XP Tutorial 1 For Noobs
http://www.crankeye.com/forums/viewtopic.php?p=55556#55556

Windows 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.

Windows

Windows 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.


Code: [Select]
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.

Code: [Select]
 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

Code: [Select]
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.

Code: [Select]
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.

Code: [Select]
class Window_Blah < Window_Base


You created a new class Window_Blah with a superclass Window_Base.

Code: [Select]
 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.


Code: [Select]
   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.

Code: [Select]
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. ******


Code: [Select]
   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.

Code: [Select]
 end


Ends the initialize method.

Code: [Select]

  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?

Code: [Select]
   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.

Code: [Select]
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:

Code: [Select]
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
Would you like to support a new rmxp community? If so then you should join:


****
Rep:
Level 91
impressive so no one have an excuse  :wink:
I'm the Alpha and the Omega, the First and the Last, the Beginning and the End.

http://qualquek.miniville.fr/
http://www.dailymotion.com/bookmarks/ojah/video/x27l78_jake-simpson-stevie-wonder-isnt-she_music

My padawan (Tsunokiette) and me :p
http://www.team-aaa.com/root/profile.php?enter_id=614556
http://www.esl.eu/fr/player/2609080/
I'm French so forgive my bad english!

******
Rep:
Level 91
a rather good one, no offence but i liked dubleax's one better, but everyone got their own taste, i guess i might have liked it better cause back then i learned things and now i already know it Oo

i think it's a very useful tut for mid level and above users who still don't know the basics of rgss, any chance you'll make a little more "advanced" tutorial? something like ,, er,, i dunno.. Oo (just think of something ? Oo)

anyways, undoubtfuly tut db you go.
holy shit my sig was big!

**
Rep:
Level 89
lol there's another part to this tut. Thanks for your thoughts.
Would you like to support a new rmxp community? If so then you should join: