slycrel / JSTileMap

TMX Map viewer for SpriteKit
Other
212 stars 34 forks source link

some tiles offset #8

Closed bens95 closed 10 years ago

bens95 commented 10 years ago

Hi, I am trying to use your library to display a tmx map that I created in the tiled tmx editor. When I load the following map (and images) using the sample app that comes in this package, the large and medium tiles are offset, while the small tileset is in the right location. The large tiles are the furthest offset, about double the medium size tiles. The tiles only seem to be offset vertically Here are the images and a dropbox link to the tmx:

peacesong_largeprops

peacesong_largeprops 2x

peacesong_mediumprops

peacesong_mediumprops 2x

peacesong_smallprops

peacesong_smallprops 2x

https://dl.dropboxusercontent.com/u/7947348/peacetest.tmx

ps. I am pretty sure that I am using the @2x designations correctly in my code because they work well with single size, single tileset maps. (I have not tried a single size multiple tileset). Thank you for your help.

slycrel commented 10 years ago

Hi @bens95, thanks for the example. I have been able to confirm what you are seeing, it's definitely not quite right. I am not sure it has to do with the @2x images just yet. I'm already busy today, I'll probably not be able to have a deeper look at this until monday evening. I suspect it has something to do with the the way that layer drawing optimizations work and using those 3 tile sets for 5 layers.

bens95 commented 10 years ago

Thank you for the quick response @slycrel , let me know if there is anything I can do to help.

slycrel commented 10 years ago

@bens95 My apologies for the delay. I've identified one issue here, that mostly fixes the problem. In JSTileMap.m you can change line 192 -193 from this

                    sprite.position = CGPointMake(col * layer.mapTileSize.width + layer.mapTileSize.width/2.0,
                                                  (mapInfo.mapSize.height * (tilesetInfo.tileSize.height)) - ((row + 1) * layer.mapTileSize.height) + layer.mapTileSize.height/2.0);

to this

                    sprite.position = CGPointMake(col * layer.mapTileSize.width + layer.mapTileSize.width/2.0,
                                                  (mapInfo.mapSize.height * (layer.mapTileSize.height)) - ((row + 1) * layer.mapTileSize.height) + layer.mapTileSize.height/2.0);

This fixes the odd height thing you are seeing as it's using the proper coordinates now. However the grass edges are still not working properly after this which may be another issue. I'll look at it some more tonight. Thanks for your patience.

bens95 commented 10 years ago

@slycrel Sweet, thanks for the update.

bens95 commented 10 years ago

If it helps, it looks like the tiles are off by exactly one small tile up and one to the right..

slycrel commented 10 years ago

@bens95 I've gone ahead and pushed the above change to the main repo. Unfortunately I haven't been able to track down what the other problem is we are seeing. I haven't given up though. I'll let you know if when I find something.

bens95 commented 10 years ago

Thanks! Keep me updated and let me know if there's anything else I can do to help.

bens95 commented 10 years ago

my bad, clicked wrong buttlon lol

slycrel commented 10 years ago

No worries. Sorry it has been so long. My life is kind of nuts right now. This is still on my list though. =)

bens95 commented 10 years ago

So I just took another look at the map and it looks like everything is off by a little bit (assuming that the first block is supposed to be centered at (0,0)). The large blocks (red) look like they are 1/2 of a small block upwards and right. The medium blocks (green) are 1 small block up and right. The small blocks (blue) are 1.5 small blocks up and right. The white block I put in there is just a point of reference for a small block centered at 0,0. capture Alternatively, if the first block is supposed to have it's bottom left corner at (0,0): medium is centered, small is 1/2 up and right, large is 1/2 down and left.Again, white is just for reference and is centered 1/2 down and left.

capture2

Take your time, I hope this helps.

edit: sorry, the second image is not with the bottom left corner at (0,0), its with the smallest block centered at (0,0) and the other blocks placed relatively. Similarly, the second image is not all of the blocks centered, the largest is centered and the rest are placed relatively.

bens95 commented 10 years ago

This is an image with the bottom left corners at (0,0) and it seems to match up the best with the rest of the map. I am pretty sure that the smallest blocks are in the right place, the medium are off by 1/2 down and left, and the large are off by 1 down and left. capture3

ps. white is still at 1/2 block down and left, but since I shifted the rest of the blocks left and right to place their corners at (0,0) it appears different.

slycrel commented 10 years ago

@bens95 I believe I have fixed the issue with my latest commit. The problem was that the overall tile size of the map was being used to center a tile in it's proper position. I am now using the tile set's actual tile size rather than the overall map tile size and it seems to be working. Please let me know if this fixes the issue for you.

If you don't mind I would like to add the test map listed here to the project as an ongoing test for this issue. Would that be okay with you?

bens95 commented 10 years ago

Sure, feel free to add the map and images to the project. I'll test out the new commit tonight/tomorrow. Thanks again for your help.

slycrel commented 10 years ago

Thanks! And again, sorry for the long wait!