#168421 - Tommmie - Tue Apr 28, 2009 8:59 pm
ok, so i tried to get meta tiles working, but they do it for 50%(it is cut down half the height, my function(it's a 256x256 bg):
Code: |
unsigned short vrammap[1024];
void initmetabg(void){
int ix, iy; // teller variabelen
int meta, dest; // locatie variabelen
for(iy = 0; iy < 16; iy++)// nu zijn er maar 16 tiles(meta!)
{
for(ix = 0; ix < 16; ix++) // hier geld hetzelfde
{
meta = testscrnMetaMap[(iy * 16) + ix]; // reken uit welke metatile gecopieerd moet worden
dest = (iy * 16 * 2) + (ix * 2); // reken de beginplek in de vrammap uit
vrammap[dest + 0] = testscrnMetaTiles[meta * 4 + 0];
vrammap[dest + 1] = testscrnMetaTiles[meta * 4 + 1];
vrammap[dest + 32] = testscrnMetaTiles[meta * 4 + 2];
vrammap[dest + 33] = testscrnMetaTiles[meta * 4 + 3];
}
}
} |
[/code]
#168422 - DiscoStew - Tue Apr 28, 2009 9:48 pm
I think when calculating "dest", it should be
Code: |
dest = (iy * 32 * 2) + (ix * 2); |
A 256x256 bg is composed of 32x32 tiles, so for each row, you jump a total of 32 tiles, but because you are constructing a scene made with 16x16 pixel meta tiles, you have to make an additional jump of 32 tiles to skip the 2nd row of the placed meta tiles. So, just replace the "16" with "32"
_________________
DS - It's all about DiscoStew
#168551 - Tommmie - Mon May 04, 2009 8:14 pm
thanks discostew! worked finally. but now something else, but related to meta tiles: I want to have a dynamic scrolling bg with meta tiles. So i have an 512x256 bg init in my code an i copy some riows or colums of the bg when needed. but i have this function now for adding a column, but there is something wrong(I can't find it, already 3 days searching), namely the bgś will be cut down in half as in the last post.
this copy's a colum into the vrammap of the bg when needed:
Code: |
unsigned short vrammap[2048];
unsigned short metatiles[24];
unsigned short metamap[512];
void metacpy(int pos, const u16 * meta){
vramblock[pos + 0] = mmap[(*meta) * 4 + 0];
vramblock[pos + 1] = mmap[(*meta) * 4 + 1];
vramblock[pos + 32] = mmap[(*meta) * 4 + 2];
vramblock[pos + 33] = mmap[(*meta) * 4 + 3];
}
void bg_metacolcpy(int tx, int ty, int bg, int width)
{
int iy;
int vramX = (u32) (tx / 16) % 32; // because the bg i have inited is 32 meta tiles wide
int vramY = (u32) (ty / 16) % 16; // the same, but now the bg is 16 meta tiles high
vramX = (vramX / 16) * 32 * 32 + (vramX % 16) * 2; // first iḿ calculating if i have to copy it in the second block of the map and then i'm adding the extra tiles
int pos = (vramY * 32 * 2 + vramX); // integer to destination
const u16 * metatile = &map[tx / 16 + ((ty / 16) * 32)];
for(iy = vramY; iy < 16; iy++)
{
metacpy(pos, metatile);
metatile+= width;
pos += 64; // 2 rijen verder(meta tile is 16 pixels hoog!
}
pos -= 1024;
for(iy = 0; iy < vramY; iy++)
{
metacpy(pos, metatile);
metatile += width;
pos += 64;
}
}
|
#168554 - DiscoStew - Mon May 04, 2009 10:40 pm
When dealing with Text BGs, you need to understand that it is sectioned off into 32x32 blocks, like so...
Code: |
256x256
*****
* 0 *
*****
512x256
*********
* 0 * 1 *
*********
256x512
*****
* 0 *
*****
* 1 *
*****
512x512
*********
* 0 * 1 *
*********
* 2 * 3 *
********* |
For 256x256, there's no problem. With 512x256, you need to think of the entire thing as 2 256x256 blocks connected horizontally. Editting a tile in column 0 to 31 is like editting a tile in a regular 256x256 BG, but editting a tile in column 32 to 63, you have to add an entire BG block's worth of tiles, which would be 32x32 tiles. In 256x512, they are connected vertically, but the method to editting this type of BG isn't much different from a 256x256, because it is extended vertically. With 512x512...well, you get the idea.
_________________
DS - It's all about DiscoStew
#168556 - Dwedit - Tue May 05, 2009 12:56 am
If your metatiles are not aligned to a 2x2 boundary, you will get incorrect behavior when you go off the edge.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#168561 - Tommmie - Tue May 05, 2009 2:55 pm
solved it, was the init function to load the first tiles of the bg. but thanks for the help!
#168865 - Tommmie - Mon Jun 01, 2009 8:04 am
my fault it's already solved