Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Artifact/Tearing Problem with LibGDX  (Read 9890 times)
0 Members and 1 Guest are viewing this topic.
Offline Bukky

Junior Newbie

« Posted 2013-05-10 03:44:29 »


I'm currently working on a simple side-scrolling game for my software engineering class. I've been working on the graphics lately and being able to resize the screen while having the aspect ratio stay the same. Everything is working fine with the resizing, but once I begin resizing it, I get weird lines between my tiles. Here's a picture:

I checked out this thread below which seemed similar, but most of the proposed solutions did not seem to work for me.

I tried rounding the camera coordinates before sending it to the SpriteBatch but that didn't help. I'm loading the tiles from a single Texture and splitting them up into an array of TextureRegions, but the pink color of the line artifact is from a neighboring tile to the dark purple one seen here. If I change the pink tile to gray, sure enough the line artifact changes gray. I tried loading the texture with different filters but nothing worked. I feel like it must be something with the texture though because of the way its sampling the texture outside of its region.

Now that I think about it, I haven't really seen many games allow you to stretch the window to whatever size you want. Is this why perhaps? Maybe I should just have a couple different scales that are stable, to scale the resolution up by? Here is the resize method from my Game class (implementing ApplicationListener from gdx). The code is taken off a tutorial I found, I can try to find the link for it if anyone wants.

   public void resize(int width, int height) {
      float aspectRatio = (float) width / (float) height;
      float scale = 1f;
      Vector2 crop = new Vector2(0f, 0f);

      if (aspectRatio > Screen.ASPECT_RATIO) {
         scale = (float) height / (float) Screen.SCREEN_H;
         crop.x = (width - Screen.SCREEN_W * scale) / 2f;
      } else if (aspectRatio < Screen.ASPECT_RATIO) {
         scale = (float) width / (float) Screen.SCREEN_W;
         crop.y = (height - Screen.SCREEN_H * scale) / 2f;
      } else {
         scale = (float) width / (float) Screen.SCREEN_W;
      } crop.x, (int) crop.y, (int) (Screen.SCREEN_W * scale), (int) (Screen.SCREEN_H * scale));

Thanks for your help!
Offline theagentd
« Reply #1 - Posted 2013-05-10 05:37:27 »

Looks like texture bleeding to me. Do you have bilinear filtering enabled? What is the resolution of your texture?

Offline Bukky

Junior Newbie

« Reply #2 - Posted 2013-05-10 06:21:52 »

Ya, from a cursory google search that's probably what it is, I didn't know the proper term. I'm using a 128x128 texture with 32x32 tiles, here it is:

I'm pretty sure LibGDX defaults to Filter.Nearest, but I made sure when I loaded the texture that is to be split into multiple TextureRegions, I set its filtering to Nearest. Though I'm unsure if that's the proper way to do it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2013-05-10 11:34:11 »

I don't have that much experience with LibGDX but could you post your tile rendering code? Also, could you tell me how the bleeding behaves? Does it shimmer when you move the camera too?

Offline Bukky

Junior Newbie

« Reply #4 - Posted 2013-05-10 23:50:07 »

It was happening with any of my TextureRegions I found out, and yes it shimmered when the camera moved, as well as appeared in different locations. I ended up trying out this technique below and the bleeding is gone, though I tweaked the coordinates of the region.setRegion line a little bit (from .5f to .01f), and I don't understand whats happening exactly. It seems like it is just tightening up the region by a subpixel amount. Though when it was adding and subtracting .5f it was shaving of a whole pixel in most cases so my tiles had a line of transparent pixels in between each.
Offline theagentd
« Reply #5 - Posted 2013-05-11 09:06:06 »

I don't have any experience with libGDX. How are you drawing your sprite?

Offline badlogicgames

« JGO Bitwise Duke »

Medals: 82
Projects: 2

« Reply #6 - Posted 2013-05-11 09:07:08 »

you need to duplicate the borderpixels of each tile. libgdx's texturepacker can do that for you. - musings on Android and Java game development
Offline theagentd
« Reply #7 - Posted 2013-05-11 09:26:47 »

Really? He shouldn't need to do that in my opinion... >_>

Offline Cero
« Reply #8 - Posted 2013-05-11 09:35:08 »

you need to duplicate the borderpixels of each tile. libgdx's texturepacker can do that for you.

oh it can ? need to read the options again I guess

Edit: Ah yes and I can see that this is default actually... edgepadding

Offline Bukky

Junior Newbie

« Reply #9 - Posted 2013-05-11 22:33:59 »

Ya I was using the texture packer and it was doing that by default, but I didn't feel like splitting up all my tiles and animations into separate images. This other fix looks good enough I think.
Pages: [1]
  ignore  |  Print  

hadezbladez (695 views)
2018-11-16 13:46:03

hadezbladez (342 views)
2018-11-16 13:41:33

hadezbladez (677 views)
2018-11-16 13:35:35

hadezbladez (167 views)
2018-11-16 13:32:03

EgonOlsen (2359 views)
2018-06-10 19:43:48

EgonOlsen (2460 views)
2018-06-10 19:43:44

EgonOlsen (1461 views)
2018-06-10 19:43:20

DesertCoockie (2126 views)
2018-05-13 18:23:11

nelsongames (1888 views)
2018-04-24 18:15:36

nelsongames (2557 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!