Demonstration of the ability to copy-and-paste pixels

Programming Game Boy Games using GBDK: Part 3, Using GBTD and GBMB

 

Part 1: Configuring, Programming, and Compiling

Part 2: Placing Tiles and Moving Sprites

Part 3: Using GBTD and GBMB

Part 4: Colliding Sprites and Project Management

Part 5: ROM Banking

Graphical Tables

As discussed in both Part 1 and used in Part 2, the Game Boy has a limited amount of graphical storage. You can only have 256 tiles of 8×8 pixels. This limits what you can do and, more importantly, dictates how you compose tiles on the screen as a result.

However, as glossed over in Part 2 and now explained in Part 3, you can generate the tiles and maps themselves using two sets of tools GBTD and GBMB.

Game Boy Tile Designer

Demonstration of the ability to copy-and-paste pixels
Demonstration of the ability to copy-and-paste pixels

Found here, the Game Boy Tile Designer will be your very best friend when it comes to create and exporting tiles. Beyond simply allowing you to design — hence the word in the title — tiles, it also allows you to copy them from one slot to another and, most importantly, uses functionality called “Split Paste” to paste content from another image program into 8×8 tiles.

For example, for Part 2, I used the following set of tiles I developed in another program. From there, I selected the whole image and copied it into the Windows clipboard.

Alphabet Tiles
Alphabet Tiles

Split-Pasting

In GBTD, go to Edit -> Split Paste.

Using the Split Paste functionality
Using the Split Paste functionality

 

Now, all of the tiles have been arranged as an increasing set starting from what position was selected from the right-hand side. (In this case, the first, 0, position.)

 

Tiles copied from another program into GBTD
Tiles copied from another program into GBTD

Exporting

Once that is done, it is a matter of “including” them in a Game Boy program. To do that, go to File -> Export To.

"Export to" File-menu option
“Export to” File-menu option

On the next screen, click on the drop-down menu and choose the “GBDK C file (*.c)” option.

Selecting GBDK 'C' Source
Selecting GBDK ‘C’ Source

Select “Browse” to find the location and give the file a name. As well, change the label to something useful and finally, as a last step, set the number of tiles to export in total in the “From” field. (In this example, it is 47 tiles.)

Exporting options for GBTD
Exporting options for GBTD

Once exported, the “alpha” tile set will look much like the “alpha.c” file from Part 2.

alpha.c

Note: The above, pasting and exporting, were the exact steps I performed to generate the files for Part 2.

Once exported, be sure to File -> Save the set as “alpha.gbr”. (The result will be used in the next step and will allow you, when re-opening the file, to use File-> Export in the future, or simply Ctrl-E as a shortcut to update the file.)

Game Boy Map Builder

Two examples of 'maps' from GBDK
Two examples of ‘maps’ from GBDK

Like with GBTD, the GBMB can also be found on the same site.

GBTD and GBMB are created to feed into one another. The files saved from GBTD can be opened by GBMB to use the tile to create larger ‘maps’ of areas or as part of the creation of a meta-sprite, a sprite made up of multiple tiles.

In our example, go to File -> Map Properties and select the file created in GBTD, “alpha.gbr”

Map Properties for GBMB
Map Properties for GBMB

When asked for width and height, use 10×2.

"alpha.gbr" loaded in GBMB
“alpha.gbr” loaded in GBMB

Placing Tiles

In GBMB, the left-click is used to select a tile from the right-hand list of perform an action from the left-hand listing. Right-clicking places a tile on the map.

Using tile 48 as a 'blank' tile
Using tile 48 as a ‘blank’ tile

Continuing from the discussion from Part 2, we can use the fact that tile 48 is ‘blank’ to use it as a way to make the map ‘blank’ to start.

"HELLO WORLD" written using tiles
“HELLO WORLD” written using tiles

Then, using one letter at a time, we can write “HELLO WORLD” on the map.

Exporting

Once we have the map arranged as we like, we can export the map like in GBTD through the File -> “Export to…” option.

"Export to" File-menu option
“Export to” File-menu option

Also like in GBTD, select the “GBDK C file (*.c)” option, use “Browse” to set a location and name, and set a label.

Exporting to C source
Exporting to C source

Unlike in GBTD, click on the “Location format” tab and set “1 plane (8 bits)” and, in the properties, select “Tile number” from the drop-down menu. Once done, click the “OK” button.

Setting Plane, 8-bits and tile number
Setting Plane, 8-bits and tile number

The resulting file, much as “alpha.c” using GBTD was “alpha.c” from Part 2, “helloWorld.c” will be the same except for the addition of the header comment information.

helloWorld.c

Once exported, be sure to File -> Save the map. This will save you time in re-creating it and, like with GBTD, will remember the location you saved the file and allow for quick File -> Export or Cntl-E exporting.

Combining Everything

Unlike Part 1 or Part 2, there are no code changes to “main.c” in this Part. However, it is included here for reference.

main.c

Note: The creation of “blankScreen.c” and “sprites.c” are not shown in this post. However, given the techniques explained, their creation, as a 20×18 map of tile 48 and sprites drawn as tiles, is fairly self-explanatory.

In Part 4, I will cover the basics of colliding sprites and project management.