Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 2411 times)
0 Members and 1 Guest are viewing this topic.
Offline Bukky

Junior Newbie





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

Hi JGO!

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:
http://i.imgur.com/ymlBAsj.png

I checked out this thread below which seemed similar, but most of the proposed solutions did not seem to work for me.
http://www.java-gaming.org/topics/solved-white-lines-tearing/27958/view.html

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
   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;
      }

      Gdx.gl.glViewport((int) crop.x, (int) crop.y, (int) (Screen.SCREEN_W * scale), (int) (Screen.SCREEN_H * scale));
   }


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

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

Myomyomyo.
Offline Bukky

Junior Newbie





« Reply #2 - Posted 2013-05-10 08: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 13: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?

Myomyomyo.
Offline Bukky

Junior Newbie





« Reply #4 - Posted 2013-05-11 01: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.

http://www.wendytech.de/2012/08/fixing-bleeding-in-libgdxs-textureatlas/
Offline theagentd
« Reply #5 - Posted 2013-05-11 11:06:06 »

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

Myomyomyo.
Offline badlogicgames
« Reply #6 - Posted 2013-05-11 11:07:08 »

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

http://www.badlogicgames.com - musings on Android and Java game development
Offline theagentd
« Reply #7 - Posted 2013-05-11 11:26:47 »

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

Myomyomyo.
Offline Cero
« Reply #8 - Posted 2013-05-11 11: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-12 00: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (13 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (26 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!