Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (236)
games submitted by our members
Games in WIP (865)
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 LibGDX: gaps between tiles when rotating them  (Read 11519 times)
0 Members and 1 Guest are viewing this topic.
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Posted 2014-10-23 09:42:19 »

Hi folks,

I have run into an issue with a tile grid I cannot seem to solve: gaps / lines appear between tiles when I rotate the grid. I think it has something to do with texture filtering, but cannot figure out how to solve it. The grid is a spaceship built out of tiles (hence why the grid has to rotate).

Here's how the tile grid looks without rotating:

And here's how it looks while rotating:


I'm using LibGDX and the textures are on a texture atlas with the following pack settings:
1  
2  
3  
4  
5  
6  
{
      wrapX: Repeat,
      wrapY: Repeat,
      filterMin: Linear,
        filterMag: Linear
}


This is the code I use to render the ship / grid:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
Matrix4 m4 = new Matrix4();

   void drawShip(Ship ship, SpriteBatch batch) {
      float shipX = ship.body.getPosition().x * Constants.BOX2D_TO_SCREEN;
      float shipY = ship.body.getPosition().y * Constants.BOX2D_TO_SCREEN;
      float angle = ship.body.getAngle();
      m4.setToTranslation(shipX, shipY, 0);
      m4.rotateRad(0, 0, 1, angle);
      batch.setTransformMatrix(m4);
      int designWidthPx = ship.design.width * Constants.CELL_SIZE_PX;
      int designHeightPx = ship.design.height * Constants.CELL_SIZE_PX;
      for (int x = 0; x < ship.design.width; x++) {
         for (int y = 0; y < ship.design.height; y++) {
            Module module = ship.cells[x][y].module;
            if (module != null && ship.design.cells[x][y].topLeft) {
               TextureRegion tex = module.texture;
               batch.draw(tex, x * Constants.CELL_SIZE_PX - designWidthPx / 2 - Constants.CELL_SIZE_PX / 2, y
                     * Constants.CELL_SIZE_PX - designHeightPx / 2 - Constants.CELL_SIZE_PX / 2,
                     Constants.CELL_SIZE_PX / 2, Constants.CELL_SIZE_PX / 2, Constants.CELL_SIZE_PX,
                     Constants.CELL_SIZE_PX, 1f, 1f, directionToDegrees(ship.design.cells[x][y].direction));
            }
         }
      }
      m4.idt();
      batch.setTransformMatrix(m4);
   }

   public float directionToDegrees(int direction) {
      return -90f * direction;
   }


Does anyone have an idea on how I could resolve this?

Offline Drenius
« Reply #1 - Posted 2014-10-23 13:29:09 »

Am a friend of hackish solutions, tell me I'm wrong, but couldn't you just let them overlap a little bit? Should at least remove the problem...
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #2 - Posted 2014-10-23 13:40:43 »

Hmm, that might just work. However, I would prefer a somewhat less hackish solution Wink

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

Junior Devvie


Medals: 2
Exp: 3 years



« Reply #3 - Posted 2014-10-23 13:57:21 »

Probably wrong but could it be a floating pointing rounding error. In tile maps if you position tiles with floats you sometimes get gaps.

Just a guess Sad
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #4 - Posted 2014-10-23 14:08:56 »

Thanks for the tip, I had thought of that as a possible cause. However, luckily, my Google-Fu-skills paid off and I found the answer. Turns out on the TextureAtlas that contains my tiles there's transparent pixels directly next to the tiles. While using linear filtering these pixels are also sampled and as a result the edge pixels of each tile are also made partially transparent.

The solution is easy, in case anyone else runs into this. Repack your textures using the duplicatePadding: true setting, which will duplicate the border pixels into the padding space next to it. The problem then goes away!

1  
2  
3  
4  
5  
6  
7  
{
      wrapX: Repeat,
      wrapY: Repeat,
      filterMin: Linear,
      filterMag: Linear,
      duplicatePadding: true
}

Pages: [1]
  ignore  |  Print  
 
 

 
Riven (181 views)
2019-09-04 15:33:17

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

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

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

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

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

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

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

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

nelsongames (4287 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

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
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!