Tiled map with more than 1 tileset not rendering correct

Anything libgdx related goes here!

Tiled map with more than 1 tileset not rendering correct

Postby pato22 » Mon Jan 06, 2020 2:30 am

i am trying to create a map in tiled with tilesusing 2 diferent tilesets.
When using either alone the map renders correctly, however from the moment that the tmx file has more than one tileset the game only renders the tiles from one tileset and not even the correct tile just the tile in the posion (tile+the other tileset size)

eg:
Tileset 1 size 4 (1 to 4)
Tileset 2 size 5 (5 to 9)

1,1,1
5,5,5
1,1,1

renders to ->

5,5,5
9,9,9
5,5,5

Any help or sugestions?
Thanks in advance
pato22
 
Posts: 6
Joined: Mon Jan 06, 2020 2:14 am

Re: Tiled map with more than 1 tileset not rendering correct

Postby shatterblast » Mon Jan 06, 2020 4:36 am

If I understand correctly, your TiledMap contains different sized tiles for one set. This is wrong. It's okay to have different sized sets for scaling an entire mapping either up or down. However, you want to keep the same exact size for each Texture, going into your current mapping.

If this makes sense, what if you took a picture of yourself? What if your left arm suddenly looked x100 the size of your body? You would recognize it as wrong. The software thinks that way about the Texture sizes of your tiles. Again, you can have different sizes of Texture objects for different TiledMapTileSet objects, but a TiledMap object needs identical sizes for every Texture in your given set. One TiledMap object generally accepts one TiledMapTileSet, although it's possible to bend the "rules" by both extending Texture into your own custom class and adding stuff.

It's generally a much better idea to overlap one TiledMap object over another instead of trying to stack Texture objects in one. You can place your passive "background" TiledMap object into a secondary Stage behind your primary one if you prefer. In that way, your intended Actors the player controls only interact with your primary TiledMap object. You can set some fancy collision detection if you want to include the relatively passive TileMap in your action. A Listener can help.

If you want to create unique Actors to interact with, like a floating platform that bounces from left to right and back again, then treat them separately. You might even put them in a separate Stage if you prefer.

I seem to give this link out a lot lately, but fortunately, Zelda doesn't care... Link 4) has a valid working example of TiledMap in action. Link 5) is a guide.

1) https://github.com/libgdx/libgdx/wiki/Tile-maps
2) https://libgdx.badlogicgames.com/ci/nig ... edMap.html
3) https://libgdx.badlogicgames.com/ci/nig ... leSet.html
4) https://github.com/bornander/nine-levels
5) http://www.pixnbgames.com/blog/libgdx/h ... e-tileset/
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Tiled map with more than 1 tileset not rendering correct

Postby pato22 » Mon Jan 06, 2020 11:33 am

Thank you shatterblast for you recomendations.
However the textures(tiles) are all the same size. The size difference is the number of tiles from each tileset.
In fact using tiles from only one tileset in the same map were using both didn't work, works perfectly.

Even using each set in different layers of the same map doesn't work either.
pato22
 
Posts: 6
Joined: Mon Jan 06, 2020 2:14 am

Re: Tiled map with more than 1 tileset not rendering correct

Postby shatterblast » Mon Jan 06, 2020 12:57 pm

What are you using as your relative measure? It might relate to your Viewport.
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Tiled map with more than 1 tileset not rendering correct

Postby pato22 » Mon Jan 06, 2020 1:24 pm

All tiles are 64*64 pixels

Definition
Code: Select all
tiledMap = new TmxMapLoader().load("maps/map2.tmx");
float unitScale = 1 / 1f;
orthogonalTiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap,unitScale);


Resize
Code: Select all
@Override
public void resize(int width, int height) {
   super.resize(width, height);
   camera.setToOrtho(false, width,height);
   camera.update();
}


Extract from render
Code: Select all
orthogonalTiledMapRenderer.setView(orthographicCamera);
orthogonalTiledMapRenderer.render();


map2.tmx
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.3.1" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="20" height="20" tilewidth="64" tileheight="64" infinite="0" nextlayerid="5" nextobjectid="1">
 <tileset firstgid="1" source="tilesets/path.tsx"/>
 <tileset firstgid="5" source="tilesets/TD.tsx"/>
 <layer id="4" name="Tile Layer 2" width="20" height="20">
  <data encoding="csv">
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,1,1,1,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,1,1,1,1,5,1,1,1,1,5,5,5,5,5,
5,5,5,1,1,1,1,5,5,5,5,5,5,1,1,5,5,5,5,5,
5,5,5,1,1,5,5,5,5,5,5,5,1,1,5,5,5,5,5,5,
5,5,5,1,1,1,5,5,5,5,1,1,1,5,5,5,1,5,5,5,
5,5,5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,
5,5,5,5,5,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
</data>
 </layer>
</map>
pato22
 
Posts: 6
Joined: Mon Jan 06, 2020 2:14 am

Re: Tiled map with more than 1 tileset not rendering correct

Postby shatterblast » Mon Jan 06, 2020 1:41 pm

Thank you for the code, but is your entire display becoming larger than you want? Or do you have one image that stays the same, while the rest of your Texture stuff in your TiledMap objects grow?

I need your point of reference if that makes sense. If you're not sure what I mean, then can you, please, link to a couple of screenshots from a before and after?

It just sounds like to me so far that your Viewport is either smaller or larger than what you want.
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Tiled map with more than 1 tileset not rendering correct

Postby pato22 » Mon Jan 06, 2020 3:51 pm

pato22
 
Posts: 6
Joined: Mon Jan 06, 2020 2:14 am

Re: Tiled map with more than 1 tileset not rendering correct

Postby shatterblast » Mon Jan 06, 2020 5:03 pm

Sorry. The two pictures don't look anything alike to me. What the difference between the first and second?
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Tiled map with more than 1 tileset not rendering correct

Postby pato22 » Mon Jan 06, 2020 5:09 pm

Thats the problem is the same map in the editor and in the libgdx game. But libgdx dont render the correct tiles as i explain in the first post
pato22
 
Posts: 6
Joined: Mon Jan 06, 2020 2:14 am

Re: Tiled map with more than 1 tileset not rendering correct

Postby shatterblast » Mon Jan 06, 2020 7:01 pm

It seems then that your game fails to find resources correctly from one of your .TSX files. By default, it's good to keep an image file referred to by a .TSX in its same folder.

I assume you have a file named similarly to either "path.png" or "TD.png" missing from your "filesets" folder in your project. Even if you don't have them in the same folder, you need to make sure your .TSX file in question points to the correct location of your necessary image.

In Link 1) below, you can find an example pair of "tiles.tsx" and "tiles.png".

1) https://github.com/libgdx/libgdx/tree/m ... maps/tiled
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Next

Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest