gbdk_playground/z_gbdk_playground_original/background
2020-07-11 08:41:14 -05:00
..
background.c Initial Commit 2020-07-11 08:41:14 -05:00
bg_data.c Initial Commit 2020-07-11 08:41:14 -05:00
bg_data.pcx Initial Commit 2020-07-11 08:41:14 -05:00
docs.sh Initial Commit 2020-07-11 08:41:14 -05:00
Makefile Initial Commit 2020-07-11 08:41:14 -05:00
README.md Initial Commit 2020-07-11 08:41:14 -05:00
screenshot.png Initial Commit 2020-07-11 08:41:14 -05:00

Background

Renders a full-screen background image.

Source


#include <gb/gb.h>

#include "bg_data.c"
#include "bg_data.map"

void main() {

First load the tile patterns in the Background Tile Pattern table. This means that we load all the 8x8 images that make up our picture (131 of them to be exact).

    set_bkg_data(0, 131, tiledata);

    VBK_REG = 1;
    VBK_REG = 0;


Then we set the tile pattern in the background tile table. The variable tilemap contains an array of tile numbers that reference to the the tiles we loaded previously using set_bkg_data.

Our image is 20 tiles wide and 18 tiles high, thus having a total of 360 tiles. How is that possible when we only loaded 131 tiles?

Well, that is because some in the image are identical. So instead the tile is only saved once in the tiledata variable and reused multiple times in the tilemap variable.

    set_bkg_tiles(0, 0, 20, 18, tilemap);

In order for the background to actually show up we call SHOW_BKG.

    SHOW_BKG;

    DISPLAY_ON;
}