Homebrew Loading tiles from tileset to background libnds

  • Thread starter Thread starter DerSamelt
  • Start date Start date
  • Views Views 923
  • Replies Replies 6

DerSamelt

Member
Newcomer
Joined
Mar 8, 2025
Messages
13
Reaction score
2
Trophies
0
XP
64
Country
Germany
Hello, I was trying to create a tileset of 8x8 or 16x16 tiles and then trying to load them onto a background with libnds. For now I've been able to create sort of a tileset and palette with grit, but I do not know how to make practical use of them.

Any help appreciated!
 
Hi, tilesets are used alongside with maps. To find practical use of tileset is just use them in external graphical tiled map editor like tiled - here. The best if editor support rotation and mirroring of tiles because ds hardware can. When you create image in editor save it to png /bmp format convert it with grit again and you should recive the same tileset maybe with different indexing. Practical use example is when we operate tilesets that are loaded into vram, to use effects like spining gems in giana sisters, when instead of updating several places in map, we update only necessary one tile of tileset, where map references are not changing. I guess so.
 
I feel like I explained it a little unclear. What my problem is, is that I don't know how load specific tiles to the background. What I have right now are two files that grit created, one header file with all the declarations and one c file with the tileset array, where there are a bunch of... I assume color codes as well as a palette. Now I want to load these tiles onto my background.
 
Last edited by DerSamelt,
I see, maybe something like this... grit convert images to .o and .h files for the linker when program is compiled.
I added ChangeMapXY, and ChangeTileXY, but for this example can be useless...
ChangeMapXY would be usefull if tileset is prepared before.

if you want to preview tileset ignoring map entries for the tiled map image you can make function like this...
C++:
//map buffer for tileset preview
short int MapBuf[256*192];

void ShowMyTileset(int c){
    short int tilesSize = DS_TilesLen[c] / 32;
    short int t = 0;
    for(int i=0; i< 256*192; i++){
        if(t < tilesSize)
            MapBuf[i] = t++;
        else
            MapBuf[i] = 0;
    }
    dmaCopy( MapBuf , bgGetMapPtr(bg),  DS00MapLen );
    return;
}
 

Attachments

Last edited by plasturion,
Hmm, how exactly does the Code snippet work? Is the Mapbuffer every pixel or 8x8 tiles. And I see that the Array saves up mainly integers from 1-tilessize wich I don’t understand too well. (Kinda new to DS or rather libnds). When I tried it (the project with the code snippet) it just didn’t display anything (the example itself worked fine).

Appreciate your help!
 
Mapbuffer is the temporary place where we indicate new indexes for single screen (256x192screeen is grid 32x24 of 8x8 tiles).
Single map-to-tile reference have 2 bytes therefore "short int" type is used here. Tilesize referer more to amount of tiles, knowing that 32bytes is one tile in 4bpp format so we can count the amount of tiles. Just to display unique ones.
(changed to tilesAmount)

This is one of many different graphics modes. In tiled-map graphic mode we can't just lit single pixel
or even tile just like that, tiles and maps works here very dependly but it makes a good use.
Map data is the structure that grit create automaticly...
Usualy first tile is empty or transparent, and next ones are unique ones.
Single change one 8x8 tile displayed on screen is in fact changing 2 bytes reference in map.
We can have one image with 16x16 tileset and create new images just by using text arrays and MapBuf
to map 16x16 tileset on the image file map, just in case to make in example sokoban stages...
I think that would be good use for single tileset loaded to memory.
I added that example. To show next stage just display 4th image first and then press Right on dpad.
(tileset from the chinese Carrier for SV handheld)

however you were right, mapbuffer should be 64 times less than that.
This sniplet seems more tidy
C++:
//map buffer for tileset preview, default background image tiles - 768  ( 256 * 192 / 64 pixels)
const short int TilesPerScreen = 256 * 192 / 64;
short int MapBuf[ TilesPerScreen ];

void ShowMyTileset(int c){
    short int tilesAmount = DS_TilesLen[c] / 32;
    for(short int i=0; i < TilesPerScreen; i++){
        if(i < tilesAmount )
            MapBuf[i] = i;
        else
            MapBuf[i] = 0;
    //or more universal instead of DS00MapLen, better to use TilesPerScreen * sizeof (short int)
    dmaCopy( MapBuf , bgGetMapPtr(bg),  DS00MapLen );
    return;
}

...and in the attachment - the working sniplet, when you press X button ( it shows what grit exactly did with the images ).
 

Attachments

Last edited by plasturion,

Site & Scene News

Popular threads in this forum