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.

C/C++ > Tile code problem

#35406 - interdpth - Fri Feb 04, 2005 6:57 am

Oh goodie new problems! Alrighty my new problem is my tiles get displayed

like this

|\\\\\\\\\\\\\\\
|\\\\\\\\\\\\\\\\
|\\\\\\\\\\\\\\\\\
|\\\\\\\\\\\\\\\\\
-------------------

Theyshould be like
Straight down and across. Here's a pic if you don't understand what I mean

[Images not permitted - Click here to view it]
The tile code is declared as const u16 Map1_Mapdata[32 * 32];

my Display code is

for (Y=0;Y<32;Y++)
for (X=0;X<32;X++) {
BG2[Y*32+X]=Map1_MapData[(Y +1)*32+X];
}

Thank you for your help.

#35412 - AnthC - Fri Feb 04, 2005 10:13 am

I'd be guessing but it looks like you have a common off by one bug - your map data array isn't a multiple of 32

Try (modified the Y*32 to Y*31 or try for Y*32 to Y*33

for (X=0;X<32;X++) {
BG2[Y*32+X]=Map1_MapData[(Y +1)*31+X];
}

or

for (X=0;X<32;X++) {
BG2[Y*32+X]=Map1_MapData[(Y +1)*31+X];
}

If this appears to fix the squewing then I'd suggest re-processing your map and make sure is it 32 units wide.

IMO, a cleaner way to code the ugly y*32 + x would be to ensure your map is a AxB array and use a pointer to array for the BG

Which you could do like this :-

u16 (*p)[32]=(u16 (*)[32])BG; // bg map array of [][32]

Then use

p[y][x]=Map1_MapData[y][x];

Anth

#35423 - ImInABand - Fri Feb 04, 2005 2:37 pm

try this:

take out the for() loops. try this, see if it works:


memcpy( (u16 *)0x06000000, &Map1_MapData, sizeof(Map1_MapData) );

#35433 - Cearn - Fri Feb 04, 2005 4:24 pm

AnthC is probably right, the map width isn't what you think it is. It seems more like a 34 or 18 wide map. But even then the map looks strange, with the green tiles everywhere I mean. Do you have a picture of what it should look like (as well as a picture of the tileset)? And why the (y+1) in the copy loop?

#35438 - interdpth - Fri Feb 04, 2005 6:02 pm

Yeah here's the tileset pic

[img]http://www.overmyhead.net/mew3domain/kittyhacker/tile.bmp[/img]

Here's the map
[img]http://www.overmyhead.net/mew3domain/kittyhacker/map.bmp[/img]

#35441 - ScottLininger - Fri Feb 04, 2005 6:43 pm

What conversion tool are you using? Some tools do *weird* changes to the data. Try converting a single, 8x8 tile and see how large the resulting array is. If it's not exactly 64 entries, then you might need to pass in some extra parameter or use a different tool.

-Scott

#35443 - interdpth - Fri Feb 04, 2005 7:46 pm

The tiles them selves get copied in to VRAM

#35498 - Cearn - Sat Feb 05, 2005 4:36 pm

ScottLininger wrote:
... Some tools do *weird* changes to the data. ...
-Scott

Heh, no shit.

From that little blue square in the corner I have the feeling that you're using Warder1's GBA Map Edit Demo 4, am I correct? This has some very strange notions of exporting. The first one is that exporting is done in u8, as you already noticed. However, these bytes just denote 8bit tile indices, there's no palette of flipping information. This would be fine for rotational bgs, but not for text bgs. This is one case where you shouldn't use a cast to u16. The only way to use the data properly is by a loop which has a u16 destination and a u8 source.
That's one problem, now for another. Apparently the exporter works differently when you have a 16x16 tilesize. In this case it doesn't print out 32x32 bytes, but 17x17. I have the exported map in front of me and the data makes absolutely no sense at all. It would however explain the screen you are getting, though.

I suppose I could point you to my own crappy map editor which operates in a similar fashion to GBAMapEdit b4, and gets the exporting right (I think. I believe I tested it for a wide number of uses, but it has been a while), but in the end you'll probably be much better off with Nessie's far more advanced MapEd.


Last edited by Cearn on Fri Aug 19, 2005 2:12 pm; edited 1 time in total

#35522 - interdpth - Sun Feb 06, 2005 2:12 am

I like your map editor the Best Cearn. But I have a question for you I would like to ask over MSN or AIM i'm kittyhacker@hotmail.com on MSN and neko mattchan on AIM not sure if this info is not to be posted on here. So sorry Mods and Admins if it is.