Hi all,
I'm having difficulty figuring out how to do tile maps on the DS. I've looked at examples, and I see how the code, works, but there are a few main topics which elude me still:
1) How do you generate a tile map from a BMP, PNG, or other format? I know you're supposed to use grit, with the -m options, but how would grit know how "big" a single tile is on the PNG? Is it a fixed, unchangeable size all the time (ie grit always divides every picture into 16pixel x 16pixel tiles and throws away whatever doesn't divide evenly), or is there an option to change how "big" a tile is?
2) I've been trying to dissect the sample code I've found on the net as to how to specify tile mapping, but I see a lot of magic numbers like the following:
.section .rodata
.align 2
.global Layer512x256Map @ 4096 bytes
Layer512x256Map:
.hword 0x0024,0x0025,0x0026,0x0027,0x0024,0x0025,0x0026,0x0027
.hword 0x0024,0x0025,0x0026,0x0027,0x0024,0x0025,0x0026,0x0027
.hword 0x0024,0x0025,0x0026,0x0027,0x0024,0x0025,0x0026,0x0027
I was thinking a tile map would be an index to the specific tile in the processed PNG from step one....aka if I wanted to display the first tile, I would say "0", and the second tile, I would say "1", etc... am I missing something? Why is everything in hex?
3) How would one go about actually create the PNG for the tile map? I'm assuming you can lay out a 16x16 grid and start drawing in the little squares, but I'm not entirely certain this is how tile maps are produced. Would someone please enlighten me?
Anyway, if anyone can answer these "n00b" questions of mine, I would greatly appreciate it. Thanks in advance for any help.
Question about creating tile maps
Re: Question about creating tile maps
1. the ds (and gba?) hardware uses 8*8 tiles, and so grit defaults to that. however, you can tell grit that the tiles are in another format, like 16*16, and grit will convert 1 16*16 tile into 4 8*8 tiles so that you can easily use it with the ds. the options are -Mh and -Mw. look at http://www.coranac.com/man/grit/html/grit.htm for more information.
2. I dont know what that asm code does, or what the magic numbers does, or why you're looking at asm code in the first place (unless you also program in asm). there are some places where it works a bit different (like with sprites), but your idea of maps is correct. my guess would be that is either is the tilemap with the tile indexes, or the data of the tiles itself.
3. the way you say it would be best if you dont have much tiles, like in a pacman level. for bigger maps, you could just create the map and a program can create the tileset and the tilemap out of the image (I know that grit can do it for 1 image, not sure about creating a tileset out of multiple images), or you can use a map editor.
2. I dont know what that asm code does, or what the magic numbers does, or why you're looking at asm code in the first place (unless you also program in asm). there are some places where it works a bit different (like with sprites), but your idea of maps is correct. my guess would be that is either is the tilemap with the tile indexes, or the data of the tiles itself.
3. the way you say it would be best if you dont have much tiles, like in a pacman level. for bigger maps, you could just create the map and a program can create the tileset and the tilemap out of the image (I know that grit can do it for 1 image, not sure about creating a tileset out of multiple images), or you can use a map editor.
Re: Question about creating tile maps
Thanks for the help. Now that I know it's always either 8*8 or 16*16, I can tailor everything accordingly. As for the assembly code, no, I'm not looking to program in assembly, but it is the only place where I can see the definition of the tile map. The code to fill in the screen looks like this:
...and the definition looks like this:
The only map "array" which I could see for the variable was in the assembly. Like I said, I'm kinda reverse-engineering this in an attempt to get an understanding of how I can do tile mapping on my own. How would I go about specifying the tile map without going through the whole assembly route? I'd love to be able to specify the entire map in C++; that way I don't have to do the whole .bword hex stuff...
Code: Select all
#include <nds.h>
#include <TextBackgrounds.h>
int main()
{
videoSetMode(MODE_5_2D);
vramSetBankA(VRAM_A_MAIN_BG);
int bg = bgInit(0, BgType_Text8bpp, BgSize_T_512x256, 0,1);
dmaCopy(TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
dmaCopy(TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
u16* map = (u16*)bgGetMapPtr(bg);
for(int iy = 0; iy < 24; iy++)
{
dmaCopy(&Layer512x256Map[iy * 64], &map[iy * 32], 32*2);
}
return 0;
}
Code: Select all
#define Layer512x256MapLen 4096
extern const unsigned short Layer512x256Map[2048];
Who is online
Users browsing this forum: No registered users and 18 guests