EDIT (9:23pm): Ah, sweet success. Thank you very much! After a few hours of trial and error (sigh -.-) and a couple google searches for examples, I came up with something that works:
void MapInit ( int currentMap[], int width, int height)
{
dbLoadImage ( "tileset.png", 1 );
int cell = 1;
for(int H = 0; H < height; H++)
for(int W = 0; W < width; W++)
{
// First we draw the sprite, which is clipped and sized later:
dbSprite ( cell, 32 * W, 32 * H, 1);
// All the math is done here:
int cellValue = currentMap[cell - 1] - 1;
int iX = cellValue % 2;
int iY = cellValue / 2;
float fOffset = 1.0f / 2.0f;
float U = iX * fOffset;
float V = iY * fOffset;
// And here the math is used to clip the sprites:
dbSetSpriteTextureCoord (cell, 0, U, V);
dbSetSpriteTextureCoord (cell, 1, U + fOffset, V);
dbSetSpriteTextureCoord (cell, 2, U, V + fOffset);
dbSetSpriteTextureCoord (cell, 3, U + fOffset, V + fOffset);
// The clip must be resized, otherwise it will retain the original size of tileset.bmp:
dbSizeSprite (cell, 32, 32);
// And then we move on to the next cell in the map array:
cell++;
}
}
Then, to make a map, I make an array of 1's, 2's, 3's, and 4's to represent grass, water, snow, and sand, then forward it to MapInit() and bickety-bam, it works like a charm. As far as I know, though, the tileset image must be square, and then iX, iY, and fOffset must reflect the new dimensions in tiles.
In other words, my current tileset has four tiles, 2x2. So:
int iX = cellValue % 2;
int iY = cellValue / 2;
float fOffset = 1.0f / 2.0f;
If I had 16, or 4x4, it would have to be:
int iX = cellValue % 4;
int iY = cellValue / 4;
float fOffset = 1.0f / 4.0f;
Anyways, it works great. Thanks again!
neguz