RGSS: Hello World

There is an ancient folklore in computer programming that says that your first program in any language should be a ‘Hello World’ display demo. The code should be brief and straightforward, consisting of only a few lines. Without further ado, let’s follow these steps.

Preliminary Steps

  1. Open RPG Maker VX and open the Script Editor (F11).
  2. Delete every pieces of code there. Absolutely everything.
  3. Create a new entry and name it ‘My New Script’ or a similar title.
  4. Copy and paste the following piece of code in the editor.

First RGSS demo

my_sprite = Sprite.new()
my_bitmap = Bitmap.new(544, 416)
my_sprite.bitmap = my_bitmap
my_sprite.bitmap.draw_text(0, 0, 320, 300, "Hello World!", 2)

loop do
  Graphics.update
end

To display text on the screen, we use two built-in classes from the RPG Maker class library:

  • Sprite
  • Bitmap.

Beware:

The Bitmap class alone isn’t enough to display something on the screen.

For beginners in RGSS coding, understanding Bitmap and Sprite classes may be challenging. An apt analogy is a soul/body relationship, where the Bitmap object holds the data (soul), and the Sprite object is the visual container for the data (body).

One of the properties of the Sprite class is ‘bitmap’, which is essentially a Bitmap class object encapsulated within the Sprite class. This encapsulation simplifies linking of objects.

my_sprite.bitmap = my_bitmap.

This Bitmap class requires a bit more labor. We initialize it to (544, 416), which is the same dimension of the smallest screen resolution. Then we used its method draw_text to print our ‘Hello World!’ message on the screen.

Finally, 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. So, set it inside a loop statement, otherwise the screen is going to be black.

Demo on YouTube


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *