Jump to content
  • Advertisement
Sign in to follow this  

libgdx unwanted gaps btw tiles/objects

This topic is 1562 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've got a problem with using libgdx. I've packed all my images into POT atlas texture with 1024x1024 dimensions and loading it with the NEAREST filtering for mag and min.


From there I'm creating TextureRegions with NPOT-sizes ( which is OK, according to official libgdx wiki and OpenGL logics ) with sizes like 17x5, 69x69 and so on.


The actual problem is that when I move some graphical objects ( or tiles, if you will ), sometimes I see gaps between them, where no gaps should appear at all. Furthermore, the size of the gap differs through the time - it's seems to be frame-dependent or something.


I'm using standart libgdx' Screen class render( float delta ) method to organize my main cycle which is giving me 60FPS everytime. VirtualVM profiler says I'm doing pretty good with CPU and RAM - 10-20% on one core and 25Mb of RAM is used. So there's no possible lag, I suppose.


I really need help, because this thing is driving me crazy smile.png

Edited by syskrank

Share this post

Link to post
Share on other sites

Allright, after some digging and experiments here the complex solution:


To avoid gaps between objects or graphics entities in a libGDX application one should:


1. ensure to use floats everywhere - even for storing target screen resolution, to avoid unwanted casts and following precision loss; OpenGL is using floats for positioning, so should you;


2. use power-of-two textures: those with side sizes aliquot to 2^x - 32x32, 16x64, 128x256 and so on; doing so will satisfy the minimization of memory usage on GPU and will help to avoid texture coordinates distortions due to float-int casts, that may or may not happen whithin the rendering process ( whatch for your shaders and datatypes );


3. use POT textures even if documentation says that you can do the opposite; POTs are great;


4. try to use NEAREST filtering for loaded textures and texture atlases; this would protect you from wrong 'pixel mix', when OpenGL will try to average your color-filled pixels with transparent ones; however, for me that showed no significant results;


5. hit your artist smile.png ensure that all of your full-frame graphics elements have no transparent or half-transparent pixels at the edges - sith happens, you now smile.png


6.  use tight alignment and/or scale your objects just a little bit, so that they will overlay each other.



Hope that would help someone. Cheers.

Edited by syskrank

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!