Jump to content
  • Advertisement
Sign in to follow this  
davek20

Cracks between tiles [SOLVED]

This topic is 3543 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone. I'm having a small issue with tiling. The problem is that after a while with the player moving, small "cracks" appear between the tiles of the map. I believe that the issue is caused by using floats and accumulating errors for the positions of everything right? Is there some way to eliminate this other then using ints for positions? [Edited by - davek20 on January 5, 2009 7:57:52 PM]

Share this post


Link to post
Share on other sites
Advertisement
Are the cracks in between the tiles, or the textures? If the latter, you probably have an incorrect wrapping/filtering mode on your texture. If the former, integer coordinates are one possible solution (but they will be transformed into floats anyway by the graphics card, which only operates on floats), and another is to make the tiles share their corner vertices, which will also reduce your vertex count significantly (you might have to get clever with the texture coordinates, and you will certainly need to use a texture atlas, which you should be already).

Share this post


Link to post
Share on other sites
Assuming you're dealing with 2d tiles with floats for positions, have you tried snapping/converting the position to ints before rendering? You can still keep your actual gameplay code using floats, just draw it at the nearest int position.

Share this post


Link to post
Share on other sites
The cracks are between the actual tiles.

Here are some screen shots: The first one is fine, but when I move slightly I get the cracks (I've also noticed that the cracks are always vertical)




Right now, each tile has 4 vertices. As for the texture, it is one large texture with all the tiles on it. I'm using glDrawArrays() with the primitive as GL_QUADS and there are vertex, index and texture coordinate arrays.

swiftcoder, can you elaborate on how I might change the texture coordinates if I make the tiles share vertices?

EDIT:
OrangyTang, I just converted the drawing code to use ints, and the cracks have disappeared but it is really jerky when I move. So I don't think I will use that solution.

Share this post


Link to post
Share on other sites
Quote:
Original post by davek20
OrangyTang, I just converted the drawing code to use ints, and the cracks have disappeared but it is really jerky when I move. So I don't think I will use that solution.

It would help if we knew what kind of range the tiles are in. Usually you'd use pixel values so rounding to the nearest int shouldn't make scrolling jerky unless you're doing something wrong or you're using a different coordinate system/range. Depending on what you're doing it may also make sense to snap the camera coords to whole numbers rather than (or as well as) snapping the drawing coords. Posting relevent code snippets would be helpful too.

Share this post


Link to post
Share on other sites
Hidden
I have an identical problem with my own game. The "cracks" or "gaps" appear as the player moves around on the screen, making the tiles scroll. As far as I understand, this happens because the position for each tile is calculated separated from all previous calculations, and because floats are no exact science this results in some tiles ending up slightly out of position. A theory for a solution I have is to store the xpos/ypos-position for the previously drawn tile, and use it when you draw the second tile next to it. That way, they shouldn't "drift" away from each other. I haven't tried this myself yet, because I'm a bit lazy. :)

Share this post


Link to post
You mentioned that switching to integers made it jerky. Are you "using" integers or are you converting to integers at the last second? I use 64-bit integers to time my transformations in my OpenGL applications. I have the smoothest results by throwing all of my calculations in at once and only type-casting if I absolutely have to. Every time you divide or multiply by something with a limited number of decimal places you lose a little bit of accuracy. Do it 6 times and you lose a lot.

On that note, try __int64 and/or doubles :)

Share this post


Link to post
Share on other sites
Actually, I believe that the problem is being caused by my camera. I casted the camera position to ints (not the actual drawing positions), and that caused the scrolling to be jerky.

I just tried something and it seemed to work well (although it is rather hackish). I just take the camera position and clamp it to the nearest 0.5 value and there are no more cracks in the tile. I guess that clamping to the nearest int was too much to clamp it to.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!