I have a problem with my Tiled Maps that i have loaded into my game following this guide; https://github.com/libgdx/libgdx/wiki/Tile-maps. All is fine and dandy, i have created a collisionsystem by following a youtube tutorial, pick the tile cell right, left, above or below you depending on which direction you are going, and then check the properties of that tile, if its blocked its blocked.

The player there is standing at position 8, 8(position.x /32, and position.y /32), that position in Tiled would show the player further down if i translate the position. But the actual position on the map is rather at 8, 12. The thing is, i can continue to walk up a bit and run into this blocked tile out in the void when the character is about to run into tile 8, 12. I have the same problem at other parts of the map, but it seems that it counts 4 tiles wrong, the center pillar is blocked about 3 tiles to the left as well, and the lower part there continues left and right a bit.

I have tried adding a scale as the wiki page does to the map renderer but that didnt solve anything since it flipped out and made the map ultra small.

I dont know the causes to problems like this. The map rendering is not different from the wiki, the camera is orthographic set to the width and height of the screen and follows the characters with a few problems. The collision is the following from the youtube tutorial;

I have found nothing in my code that suggests any kind of scaling. I followed a LibGDX Tiled tutorial and did what he did, so have no idea where the error occurs. I have also checked the LibGDX wiki and found no sollutions there. When i try the scaling wound there all it does is to mess up the map to 1 x 1cm box, so that doesnt work.Even so, if it would have been scaled, everything would have been scaled, not just one of the layers?

I have found nothing in my code that suggests any kind of scaling. I followed a LibGDX Tiled tutorial and did what he did, so have no idea where the error occurs. I have also checked the LibGDX wiki and found no sollutions there. When i try the scaling wound there all it does is to mess up the map to 1 x 1cm box, so that doesnt work.Even so, if it would have been scaled, everything would have been scaled, not just one of the layers?

I think its a camera issue.If you followed DermetFan teachings, im almost sure he went through *fixing" the camera...

Looking at the bitbucket for his project to be sure, i have all camera settings just as him.

We both create a OrthographicCamera, we both instanciate it in the show method and at the same time send it to the maprenderer, we both set the camera position on the player, and we update the camera after that. And if we resize the window we change the viewport.

Well, the collision code is probably right, just show the map rendering / camera setup stuff. The problem is probably hidden there somewhere. I haven't looked at the bitbucket project you mentioned but here is how it looks in mine (stripped down to a minimum):

publicvoidrender() {mapHandler.draw();batch.setProjectionMatrix(camera.combined); // this one is important too, as you want the same projection matrix for your // sprite batch as for the mapbatch.begin();// render other stuffbatch.end();}

I had tried that before to no avail. But it seems to fix part of the problem. The map is no longer scaled, but the collision isnt working correctly. Only seem to work on some of the sides of the blocked tiles, but its different on different combinations of placed tiles. Top side is blocked all the time though. Left only when its a single tile, right only single tiles, but also works when there are tiles to the left of it, but not above or below. And bottom side never blocks. :/

The setView method takes an OrthographicCamera, not a Matrix4. It uses the combined matrix of the given camera already.

Sabomoth: You are using two SpriteBatches (batch and the one in the map renderer). A SpriteBatch is a heavy object, so you should always just have one at a time. Also, it makes it more complicated to keep track of their matrices, like you are experiencing. In the code you posted in reply #6, you used the other SpriteBatch that didn't have the combined matrix set. That's why seismic's suggestion in reply #7 fixed at least part of the problem. I suggest you to get rid of batch and use only the one from the map renderer. It's projection matrix gets set by the setView(..) method already. Also, update before you render to avoid a lag of one frame.

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