• entries
707
1173
• views
436770

# Finally...

193 views

Fringes work. Thats right, I got my fringes to calculate AND draw correctly. I had to search hi and low for a tutorial that would help some, and it came from russia. Its similiar to David Michael's tutorial, but 1 fact was different. David's article says that north should be the first bit (north, east, south, west, northwest, northeast, southeast, southwest), whereas the russian article was using west as the first bit and it works. I had to figure out the code for myself, since neither have any examples. The hard part was getting the corners to work right. But, it all works exellently, and when I get home from work today, I'll post screenshots with an explanation. Now I need to finish a small demo and then start on my game.

In other news, I'm getting a drawing tablet so that I can sketch concept art on the comp (plus, my artist/brother can do his artwork directly on the computer). Its going to be a Wacom 5x6.

I'm off to die now (Like normal, I have 2 to 3 hours before work, and I haven't slept yet. I guess I'm just practicing [wink].)

Edit: I wrote this before I went to bed and it wouldn't let me post it lol.

Also, I'd like to thank Comandore for trying to help.

## 1 Comment

Ok, it was actually pretty simple once I started working it out on paper. The tileset needs to be laid out like the one in this tutorial:
David Michael

You split your tile into 8 parts, the four sides and the four components. This allows us to store all of the info in a single byte.

Ok, I'm just going to explain the chunks of code that really matter. This is the code that sets our fringe. nDir is a number from 0 to 7. Starting with west, and going clockwise to north, east, and south. Then starting with northwest and going clockwise to northeast, southeast, and southwest.
if(m_pTiles[(Next.y * m_nMapWidth) + Next.x].m_nTileNumber > m_pTiles[(Start.y * m_nMapWidth) + Start.x].m_nTileNumber)
iFringe |= (int)pow(2, nDir);


Ok, the heart of the code is
iFringe |= (int)pow(2, nDir);

We have bit 0 through 3 representing our sides (west, north, east, and south). And then we have bit 4 through 7 representing our corners (northwest, northeast, southeast, southwest). When all apropriate bits are set, iFringe will contain the tilenumber for your corner and for your side, so we need to separate them:
unsigned int nSideFringe = m_pTiles[(nRow * m_nMapWidth) + nCol].m_nFringe;
nSideFringe &= 15;
unsigned int nCornerFringe = m_pTiles[(nRow * m_nMapWidth) + nCol].m_nFringe;
nCornerFringe &= 240;
nCornerFringe >>= 4;


This might not be the cleanest or fastest code, but its the only way I could think of doing it.
nSideFringe &= 15;


This is the decimal value for the binary 0000 1111. If you know your bit manipulation, you should know that once we AND this with our fringe tilenumber, it'll turn off the last 4 bits (our corner fringes) leaving us with out side tile number.

nCornerFringe &= 240;
nCornerFringe >>= 4;
nCornerFringe += 15;


This does the opposite of the above. 240 is the decimal value for the binary 1111 0000. Once ANDed with our fringe number we are left with our corner bits, but we need to shift them to the right, because 1111 0000 is a different number than 0000 1111. So, we bit shift to the right 4, and this gives us our corner tilenumber. The last statement just moves it past all of the side tiles.

Edit: actually, if you lay out your tileset like the one in the tutorial posted at the beginning of my post, then you need to add 16 instead of 15 to the number (in the last statement). I had accidentally switched the first tile of the second row to the end lol.

Hopefully everybody can understand that. If not, just say so and I'll try to explain it a little better.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account