jeudi 2 octobre 2008

Text in Tiles

Liranuna used a 16x8 arrow. (see the former blog on double tiled backgrounds)
Please try in the last example an 8x8 version, and your screen will be filled with garbage!

(Use this for the gfx2gba: gfx2gba -t8 -c16 -D -P -St.bin arrowTile.bmp
and you get the .bin thing immediately)

The arrow tile number 0 fills the screen, and that is why the first 8x8 has to be transparent, then the second 8x8 has the arrow. It still works with 8x8 tiles.

This becomes clear making letters from the arrow, adding the ASCII sequence.

You need some special character sets for this, ugly and all, an 8x8 Font.

There are a few links for this:
http://www.dspassme.com/programmers_guide/tutorial/using_tiles.html

The most deep article is this:
http://www.coranac.com/tonc/text/tte.htm#sec-bmp

In the former example you can (if they are available) ask for the letters simply like this:

calculate position in array, and take place 1 of the image (the arrow or the characters)
bg0Map[POS2IDX(7, 5)] = 1 | TILE_FLIP_Y | TILE_PALETTE(2);//color 3

calculate position in array, and take place 40 of the image (the arrow)
bg0Map[POS2IDX(7, 5)] = 40 | TILE_FLIP_Y | TILE_PALETTE(2);

Since the image found in the TONC link gives the ASCII sequence, you can use the ascii value of the character:
char* msg[] = {

"http://www.dspassme.com/",
" programmers_guide/"
};

// Draw the message on the screen.
for(i = 0; i < sizeof(msg) / sizeof(char*); ++i) {
for(j = 0; msg[i][j] != '\0'; ++j) {
sub_map[j + (i * 32)] = msg[i][j] - ' ';
}
}

(As can be seen from the dspassme link, but they dont give the whole image.)

From this starting point you can build your own characterset.
It all stays in tiles, and doesn't count on your sprites, which is quit handy because
you don't have enough sprites, if you want all our characters be present too!

So it seems like the default consoleInit, but it isn't.....we can modify!



There is one problem i encountered, the transparancy was wrong.
(Then it covers the whole screen, except for the letters.)
This was already the case with my sprites.
See the next blog for solving this, or better understanding the photoshop problem.
(It can be that new photoshops handle this without a problem, mine is old, 7.05 or so...:-)

But we can now go on: a 8x16 font, being twice as high....hmmmm what will the tiles of 8x8 do????
Well the letters are cut in half and displayed top first bottom after in the tiles, so we have
to modify the ASCII formula:


int i,j = 0;
for(i = 0; i < sizeof(msg) / sizeof(char*); ++i) {
for(j = 0; msg[i][j] != '\0'; ++j) {
bg0Map[j + (2*i * 32)] = (msg[i][j] - ' ') | TILE_FLIP_NONE | TILE_PALETTE(0);
bg0Map[j + ((2*i + 1) * 32)] = ( offset + (msg[i][j] - ' ')) | TILE_FLIP_NONE | TILE_PALETTE(2);
}
}

Code example, 8x16 characters, click on left or right
half of the screen to change the offset of the lower half of the tiles