Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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  
  LibGDX tile rendering flicker.  (Read 1197 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Posted 2013-02-26 22:29:54 »

What's up everybody? Cheesy

Ok, so i am making a top-down 2(.5)D game. My "floor" tiles are stored in a WxH array (not tiles, but their id's). When I want to render them, I use two fors (y and x) get the texture for that tile id and render it at x * Tile.TILE_SIZE (int constant). To optimize the algorithm, i calculate a start and end x and y based on camera's position (a float transformed to a integer), and render only tiles that are on the screen.

Problem:
The problem is that when i move the camera (using a calculated delta -- huge decimal number) i get a visual bug: 1 pixel gap between random rows of tiles (only horizontal gap). My assumption is that the problem is caused by that float -> integer transformation.

Could anyone tell me how can i fix this problem? Also, how can i avoid this type of problems?
Thanks!

LE: Here's one picture of what is happening.


Getting a project done is by far the most hard thing in game development.
Offline vbrain
« Reply #1 - Posted 2013-02-27 05:24:56 »

When I was working with TileMaps in libgdx, that problem only occured when I zoomed in the camera, but just rendering (no matter what tilesize I specified) was smooth. I never got around to fixing it because I started working on something else.
Online theagentd
« Reply #2 - Posted 2013-02-27 09:55:06 »

Disable bilinear filtering.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #3 - Posted 2013-02-27 11:41:15 »

I don't even think i am using bilinear filtering. Isn't default in libGDX to use GL_NEAREST when loading TextureAtlases ?

Getting a project done is by far the most hard thing in game development.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #4 - Posted 2013-02-27 13:03:17 »

I fonud as a fix casting to int the camera's coordonates, but this is messing my camera code (i am calculating a vector to player's position for a smooth camera effect). Any fix for this? Cheesy

Here's my code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
private void updateCameraPosition() {
   float targetX, targetY;
   
   if(player.getPosition().x - camera.viewportWidth / 2 < 0) targetX = camera.viewportWidth / 2;
   else if(player.getPosition().x + camera.viewportWidth / 2 > world.getLevel().getWidth() * Tile.TILE_SIZE)
      targetX = world.getLevel().getWidth() * Tile.TILE_SIZE - camera.viewportWidth / 2;
   else targetX = player.getPosition().x;
   
   if(player.getPosition().y - camera.viewportHeight / 2 < 8) targetY = camera.viewportHeight / 2 + 8;
   else if(player.getPosition().y + camera.viewportHeight / 2 > world.getLevel().getHeight() * Tile.TILE_SIZE + 8)
      targetY = world.getLevel().getHeight() * Tile.TILE_SIZE - camera.viewportHeight / 2 + 8;
   else targetY = player.getPosition().y;
   
   float dx = targetX - camera.position.x, dy = targetY - camera.position.y, dist = (float) Math.hypot(dx, dy);
   Vector3 cameraVector = new Vector3((float) Math.cos(Math.atan2(dy, dx)), (float) Math.sin(Math.atan2(dy, dx)), 0);
   cameraVector.mul(Math.max(dist / 25f, .2f));
   
   camera.position.add(cameraVector);
   camera.update();
}

Getting a project done is by far the most hard thing in game development.
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.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!