gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > changinf only a few tiles in a bg

#8980 - immortalninjak - Fri Jul 25, 2003 2:11 pm

Hi all,
experimenting with tiles with the help of the gbajunkie tutorial and wanted to know how to change only a few tiles in the bg.
In my prog I have only two tiles on a 128*128 bg.
Instead of the tutorial loop:
Code:

                temp = (u16*)map;
   for(loop = 0; loop < 16*16/2; loop++)
                     bg2.mapData[loop] = temp[loop];


I use:

Code:

                for(loop = 0; loop < 16*16/2; loop++)
                     bg2.mapData[loop] = 0x00;


and then in the getinput i have:
Code:

                      bg2.mapData[count] = 0x08;
                      count++

which should on succesive button pushes gradually change the bg from one tile to the other.

However it seem to be alternating between the two tile resulting in alternaitng stripes of the two tiles.
Can anyone tell me what I'm doing wrong?
I suspect I have some numbers wrong somewhere, but changin them seems to have little effect.
thank you for your time and help.
KK

#8983 - mtg101 - Fri Jul 25, 2003 3:30 pm

OK - given the 128x128 map size, I assume we're talking rotation backgrounds.

Each tile in rotation backgrounds is 1 byte in size, but remember that you can only write to VRAM in 16bit chunks, 16bit aligned.

So when you do:
Code:

bg2.mapData[count] = 0x08;


You're setting the mapData[count], which is a16bitvalue, to 0x0008. So that means you've set tile[count*2] to 0x08, and tile[(count*2)+1] to 0x00 (assuming I've got my endians right).

If you want to set just a single tile, you need to take acount of the 16bit writing.

Let's say count is the tile index to set. You could do something like:

Code:

int temp = 0;
if(count%2)
{
   temp = bg2.mapData[(count/2)] & 0x00ff;
   temp |= 0x08<<8;
}
else
{
   temp = bg2.mapData[(count/2)] & 0xff00;
   temp |= 0x08;
}

bg2.mapData[(count/2)] = temp;


Now of course I may have got my endians wrong, in which case you'll need to swap the if / else cases around.


Cheers
Russell
_________________
---
Speaker for the Dead

#8996 - immortalninjak - Sat Jul 26, 2003 12:13 am

ahhh,
I think I get it now, so basically:
If A B C D are the first four blocks of the Bg grid.
bg2.mapData[0] would cover both blocks A and B, and bg2mapdata[1] corresponds to C and D.
Thanks that helped alot!