Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  [SOLVED] White lines / Tearing  (Read 2631 times)
0 Members and 1 Guest are viewing this topic.
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Posted 2012-12-02 06:00:28 »

Hello gents and.... gents.

I recently started to experience white lines / tearing in my game and I dont quite no how to get rid of it.

That's how it looks like:





The grass consists of little tiles and I already figured out that the camera (libGdx) isn't happy with the float values. The FPS are capped to 100.
That's how I move the camera:

1  
2  
cam.position.set((player.x + (player.width/2)), (player.y + (player.height/2)), 0);
cam.update();


If I cast the x and y values to integer the tearing is gone, but the camera gets a little wobbly.

So right now it's either a smooth camera and tearing, or no tearing and a wobbly camera. A little nudge in the right direction would be great  Smiley
Offline davedes
« Reply #1 - Posted 2012-12-02 06:05:18 »

Try using Filter.Nearest for your images.

Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #2 - Posted 2012-12-02 06:19:23 »

Try using Filter.Nearest for your images.

Can you elaborate please?

The "Sprite" class I use doesn't seem to have a method in which I could pass a filter.

This is how I render them:

1  
2  
3  
4  
5  
public void render(SpriteBatch batch){
     
      sprite.setPosition(x, y);
      sprite.draw(batch);
   }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-12-02 06:21:47 »

Most likely used as a constructor parameter or a method in that "sprite"/image class you use maybe?

Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #4 - Posted 2012-12-02 06:24:28 »

"Filters to be used with Pixmap.drawPixmap" well bummer
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #5 - Posted 2012-12-02 06:54:10 »

Please post your entire Sprite-class or write up the way you use images in libgdx. Textures, AtlasRegions, how are you doing it. That'll make it much easier to give you a definite answer to the question.
It looks like you might have to round off some floats (don't just cast to Integer!!) when you're drawing your textures, but I can't see it from the code you've posted so far.

Try putting one of these on your values before/while you draw the terrain:
MathUtils.round(x)
MathUtils.roundPositive(x) - marginally faster, but only works on positive numbers

- Jonas
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #6 - Posted 2012-12-02 07:30:39 »

Please post your entire Sprite-class or write up the way you use images in libgdx. Textures, AtlasRegions, how are you doing it. That'll make it much easier to give you a definite answer to the question.

I am using the Sprite-class that comes with slick, and you can either use Texture or TextureRegion for it. I use TextureRegion.

-

I applied the round method to both the camera and the render x, y values for every entity and that did the trick, thank you  Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
cam.position.set(MathUtils.roundPositive(player.x + (player.width/2)), MathUtils.roundPositive(player.y + (player.height/2)), 0);
cam.update();

//--

public void render(SpriteBatch batch){
     
   sprite.setPosition(MathUtils.roundPositive(x), MathUtils.roundPositive(y));
   sprite.draw(batch);
}
Offline davedes
« Reply #7 - Posted 2012-12-02 08:20:22 »

You would set the filter using Texture and TextureFilter:
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Texture.html

 Wink

Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #8 - Posted 2012-12-02 08:55:18 »

Please post your entire Sprite-class or write up the way you use images in libgdx. Textures, AtlasRegions, how are you doing it. That'll make it much easier to give you a definite answer to the question.

I am using the Sprite-class that comes with slick, and you can either use Texture or TextureRegion for it. I use TextureRegion.

-

I applied the round method to both the camera and the render x, y values for every entity and that did the trick, thank you  Smiley
...

Does'nt that have the same effect as casting to an int?
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #9 - Posted 2012-12-02 10:45:37 »

Casting to Integer always rounds downward, so

5.2 becomes 5 and
5.8 becomes 5 aswell.

Mathutils.round() rounds properly, so

5.2 becomes 5 and
5.8 becomes 6.


Besides, I only casted the camera values to Integer and forgot about the render x and y values.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #10 - Posted 2012-12-02 21:06:24 »

The problem is most likely caused by how you calculate your tile positions in combination with float rounding.

For example, mathematically equal multiplications and additions might not equal the exact same value. For example
1  
x = y*2 + y;

might not give the exact same result as
1  
x = y*3;


The reason why I took this exact example is because that's most likely what you're doing for your sprite positions (or what LibGDX does). Consider a tile, it goes from
1  
x1 = tileX * tileSize;

to
1  
x2 = tileX * tileSize + tileSize;


However, the tile next to it at index tileX+1 will start at
1  
x1 = (tileX + 1) * tileSize;


Now there's a chance for those two to be different since
1  
2  
3  
tileX * tileSize + tileSize 
//may not be equal to
(tileX + 1) * tileSize


Rounding the values therefore eliminates the problem, but is not a very elegant solution. =S



Myomyomyo.
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #11 - Posted 2012-12-03 13:57:36 »

Thank you for the insight  Smiley
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #12 - Posted 2012-12-03 21:30:41 »

Casting to Integer always rounds downward, so

5.2 becomes 5 and
5.8 becomes 5 aswell.

Mathutils.round() rounds properly, so

5.2 becomes 5 and
5.8 becomes 6.
Indeed!

Besides, I only casted the camera values to Integer and forgot about the render x and y values.
Doh Smiley
Did you try removing the rounding from the camera after you did it for the render values? It might not be needed.

I applied the round method to both the camera and the render x, y values for every entity and that did the trick, thank you Smiley
You're very welcome Smiley

- Jonas
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.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!