Viewports can be thought of as planes and layers. A viewport is basically a surface to display objects and elements. It’s absolutely necessary to view graphics on the screen, exactly the same way as you need a piece of paper to draw stuff on it.
Here is the most basic example, type the following code inside an event on a map using the script function:
loop do
Graphics.update$viewport1 = Viewport.new(0, 0, 544, 416)
$viewport2 = Viewport.new(0, 0, 544, 416)
$viewport1.z = 50
$viewport2.z = 100$my_spriteA = Sprite.new()
$my_spriteA.viewport = $viewport1
$file = “Graphics/Battlers/Behemoth”
$my_spriteA.bitmap = Bitmap.new($file)$my_spriteB = Sprite.new()
$my_spriteB.viewport = $viewport2
$file = “Graphics/Battlers/Demon”
$my_spriteB.bitmap = Bitmap.new($file)
end
Note that the ‘z’ coordinate is the level of priority of the viewport. The larger this value, the more the viewport will be displayed above other ones.
I loaded two images. The behemoth is appearing over the demon, but if I wanted the opposite effect I would simply change the values of the ‘z’ coordinates.
P.S. The default mapping system in RPG Maker VX use 3 viewports.
• One for background tiles.
• One for overlapping tiles.
• One for tiles above the character.
Sorry, I wrote this piece of tutorial very quickly without dissecting it into detail, I hope you will be able to understand :)
Remember to replace the “ and ” for a pair of " ", otherwise you’ll get an error when running this script.
Well, let’s look at our build-in class called Window. Building a window is quite easy as RGSS2 is taking care of everything for us. It requires low intervention from the programmer. We just need to create a window object and set the properties.
Let’s talk about the database. RGSS2 has a bunch of modules labeled ‘RPG’, they contain all the basic data structures of RMVX that are used for the database.
We’re going to plot a green pixel in the middle of the screen. I used as few lines as possible to focus on the essential. Do the following steps:
1-) Open RPG Maker and open the Script Edition (F11).
2-) Delete every piece of code there. Absolutely everything.
3-) Insert a new entry and name it something like “My Program”
4-) Enter the following piece of code in the editor.
USING THE FONT CLASS
Now let’s enrich our previous “Hello World” demo. Do the following steps:
PART ONE – BASIC “HELLO WORLD!” DEMO
There is an ancient folklore in computer programming that says that your first program in any language should be a “Hello World” display program. Of course there is nothing more cheering than this type of welcoming message to push your motivation ahead with programming.
This tradition also states that this program should be very easy, as few lines as possible. So I did my best to make a ‘Hello World’ program for RGSS2.
1-) Open RPG Maker and open the Script Edition (F11).
2-) Delete every piece of code there. Absolutely everything.
3-) Insert a new entry and name it something like “My Program”
4-) Enter the following piece of code in the editor.
loop do
Graphics.update
my_sprite = Sprite.new()
my_sprite.bitmap = Bitmap.new(544, 416)
my_sprite.bitmap.draw_text(0, 0, 320, 300, “Hello World!”, 2)
end
P.S: If you copied/pasted the code, expect a slight problem with the text formatting. Remember to replace the symbols “ and ” for a pair of ” “, otherwise you’ll get an error when running this script.
So, how does it work?
First, we need to set our main code inside a loop statement. Then we use the RGSS2 built-in module ‘Graphics’ and its update method:
Graphics.update.
It refreshes the game screen and advances time by 1 frame. This method must be called at set intervals; otherwise the screen is going to be black.
To display text on the screen, we use two other built-in classes in the RPG Maker library. The name of those two classes is: Sprite and Bitmap.
‘Sprite’ allow us to display characters on the screen. ‘Bitmaps’ are expressions of so-called graphics. Therefore to display bitmaps on the screen, sprites must be used first.
Luckily, our Sprite class possesses a property called ‘bitmap’ which actually refers to the Bitmap class used for the sprite’s starting point. It makes things pretty straightforward and easy for us to use. ^^
So in our previous demo, we just had to create an object from the Sprite class through a local variable, and we simply named it my_sprite:
my_sprite = Sprite.new()
Then we used the bitmap property that refers to the Bitmap class. We initialized it to width = 544, height = 416 (the same dimension of the default screen resolution).
my_sprite.bitmap = Bitmap.new(544, 416)
We’re finally allowed to use the ‘draw_text’ method from the Bitmap class and print our “Hello World!” message on the screen:
my_sprite.bitmap.draw_text(0, 0, 320, 300, “Hello World!”, 2)
You ask: “How the heck should I know about those classes? Where are they coming from?”
Well, the RGSS build-in classes are hidden to you. It sucks, yeah… but it doesn’t matter. One efficient way to learn about those build-in classes is to open the help manual from RPG Maker (F1) and look at their definitions. Then you can surf in the RGSS Reference Manual and you will see a list of all built-in classes which act like super classes. Make sure to watch their properties and methods, it’s what truly matter. Those built-in classes are the core of RPG Maker.
So, for example, the blueprint of draw_text look like this:
draw_text(x, y, width, height, str[, align])
or
draw_text(rect, str[, align])
Feel free to make a few attempts!
Today let’s just examine the script editor. So please open it [F11] while your RMVX engine is opened. (sorry for the lack of screenshots, I felt lazy…)
The script editor is divided into 7 manageable sections:
Well, I’m intending to write some tutorials on RGSS2. Note that my time is very limited for this kind of stuff, therefore these tutorials should be considered as early drafts. I will try to stay simplistic and avoid being techie for newbies. I will certainly carry more revisions later.
First of all, you need to get familiar with the Ruby language. I cannot teach it to you, but don’t worry there are tons of good tutorials on Internet.
Make this website your starting point:
http://www.ruby-lang.org/en/
Make sure to understand how classes work: encapsulation, inheritance and polymorphism. The good news is that the learning curve of Ruby is very fast, and it has less levels of complexity than other languages such C or C++. Consequently Ruby is a good starting point to learn to build programs, and in this current case you can see results directly in RPG Maker. And trust me with C and C++ you need to learn tons of other technologies before seeing simple visual results on the screen. Ruby and RPG Maker are enough to boost your interest as a new aspirant.
I will not cover stuff in RMXP, I’m only going to explore RMVX in my tutorials, but there are many similarities between to two of them.
Before I keep going, I would like to make the point on a certain detail. My current tutorials aren’t about programming or methodologies. Most of the time my lessons are meant to be quick observations, a dissection of RGSS2. I will simply point at the strict minimum to enlighten new aspirants, and maybe inspire you to do more fancy stuff later.
Thus, in this first bunch of tutorials, we will not use the script editor. We will just enter our code via an event on the map of your game project. It’s the most appealing method that I’ve found for newbies using RPG Maker, rather than making you feel dizzy with the big script editor. Note though that my approach in this part of the tutorials can lead to extremely bad habits. I will do a lot of nasty things that wouldn’t be approved by coders in general. This could turn out into code maintenance nightmares, code duplication, hidden bugs, lack of understanding, etc. It means that, as a future responsible coder, you will need to use better code when you’ll apply my lessons in your real scripts later.
Well, let’s start!