Godot Version
4.5.1
Question
The player in my game is represented by a 32*32 icon scaled x 4.0. I have been using tiles in a tile map layer with the same size and scale. I’m using 1920x1080 for a screen size.
Recently I tried using 128*128 tiles to quickly prototype a new map. Unfortunately, with those tiles the TileMapLayer did not work correctly at all. No matter where I placed the player on the map, the position on the screen did not match where I put the player in my scene. The player icon would also continuously shift from side to side, and could also be seen as having exited the map if I placed the player near a border. Trying to move the player with the game controls did not work at all.
I tried using 64x64 map tiles scaled x 2.0, but was unable to reproduce the behavior. I am also unable to reproduce the behavior if the 128x128 tiles are used in a map that fits within the defined screen size.
I can work around this behavior easily enough, but don’t have an idea why I am seeing it. Can anyone shed some light on this?
This sounds like on the problematic map that your TileMapLayer is offset from the center of the map, and so what looks right in the editor does not when you play the game. Make sure the TileMapLayer is centered on 0,0. If doing so moves your map, then find out what node above it is moving it off-center and fix that.
I have combined tile sizes and even scaled tiles from really weird sizes to 128x128 without this problem.
I am assuming when you say centered you mean the transform should be 0,0. It is. I have even recreated the TileMapLayer multiple times and experienced the issue each time.
You say you have combined tile sizes and scaled to 128x128, but have you used a tile that size? I have no issues when I scale a map tile to 128x128.
Appreciate the feedback. This is a weird corner case with an easy workaround, but I am very curious as to what is going on and would like to learn more.
I did some more investigation and discovered what the issue was. It has nothing to do with the tile size.
The tile I was using as the floor in the tile map was set up with a collision shape. In hindsight this seems obvious given I was seeing the player being bounced back and forth, though I don’t recall ever setting up collision shapes for that tile set.
2 Likes