craftworkgames / MonoGame.Extended

Extensions to make MonoGame more awesome
http://www.monogameextended.net/
Other
1.43k stars 324 forks source link

[Tiled] TiledMap displaying wrong tiles #307

Closed craftworkgames closed 7 years ago

craftworkgames commented 7 years ago

There was a post on the forums a couple of days ago. Moved it here to capture the problem. Anyone want to look into it?

My tiled map looks as it is supposed to in Tiled Editor, but when I try to render it, it renders wrong textures for the tiles. The map with the sprite sheets: dropbox6

I'm using the latest version of MonoGame.Extended, which I compiled from the source.

The problem seems to only affect tiles which are using textures from the second sprite sheet(the indoor one).

house.zip

OptimusPi commented 7 years ago

I will look into this. I originally added support for multiple tilesets. So it's familiar with me.

OptimusPi commented 7 years ago

It's a bug. https://i.imgur.com/EUVBvHG.png Sorry about that. I must have not fixed it properly. I don't know why it's broken but I'll find out and take care of it.

craftworkgames commented 7 years ago

It would be really good if we could include the attached "house" map as one of the demo's. That way we have a way to test this feature in the future.

OptimusPi commented 7 years ago

Yes it would. Is the art okay to include, no legal issues with that? I'm guessing it might be open game art, though. I don't know why I fixed this bug for my map but it doesn't work for this one. Yet to look into it.

When I fix it, may I make a pull request to a Demo project? Thanks.

craftworkgames commented 7 years ago

Is the art okay to include, no legal issues with that?

The art looks like one of Kenney's packs so I think the license is very permissive.

License: (CC0 1.0 Universal) You're free to use these game assets in any project, personal or commercial. There's no need to ask permission before using these. Giving attribution is not required, but is greatly appreciated!

When I fix it, may I make a pull request to a Demo project? Thanks.

Yes, absolutely. It's very important to keep the demos updated. That's currently the best way we have to make sure we haven't broken anything. Any improvements to the demos are quite welcome.

jeffgamedev commented 7 years ago

I noticed when placing tiles beyond the first row of the tileset, there appears to be a calculation issue of what tile to render. It looks like an off-by-one error, per row of tiles. I made a test tileset to visualize the offset error (attached photo)

tilesoff

Just updated to the latest beta version to see if the issue I am having would be resolved. After getting up to date to 0.6.247-beta, the issue is not resolved.

My tileset image size size is 296x296. It was also occurring with my actual tileset of 297x400 with 1 pixel borders. broken

craftworkgames commented 7 years ago

@jeffol I'm surprised we haven't noticed something so obvious. There must be something different about your TMX file compared to the ones in the demos.

Could you please attach your TMX and tileset (the test tileset you made to visualize the error would be great)?

jeffgamedev commented 7 years ago

@craftworkgames For sure. I was able to resolve my issue today by resizing my tileset, but obviously the issue still exists. I've attached the test files. Sorry I didn't attach them right away, it was a bit late when I posted.

testmap.zip

craftworkgames commented 7 years ago

@jeffol Thanks mate.

<tileset firstgid="1" name="tiles02" tilewidth="16" tileheight="16" tilecount="324" columns="18">
    <image source="tiles02.png" width="297" height="297"/>
</tileset>

So as you said, the problem probably has something to do with the fact that the width and / or height of the tileset image is not divisible by 16 (the tile size).

I haven't had a change to properly look into it yet but I was able to easily reproduce the issue. Cheers.

rafaelalmeidatk commented 7 years ago

Maybe it's related? #122

OptimusPi commented 7 years ago

One strange clue, if I increase the tileset image a bit, until it's divisible by 16 (width and height), Tiled Map Editor notices this and says "Would you like to increase the tile columns by 1?" So I clicked "No" to see what it would look like. And it looks the same as the bug.

https://i.imgur.com/Js06O1y.png

I am going to look and make sure if Spacing attribute is read and applied correctly, and see if I can find a fix. Will let you know if I do.

lithiumtoast commented 7 years ago

Found the problem.

https://github.com/craftworkgames/MonoGame.Extended/blob/develop/Source/MonoGame.Extended.Tiled/TiledTileSet.cs#L40

The test map provided earlier in this issue comments has a width of 296 which does not divide evenly by 16, the tile size.

I'll fix this.

EDIT: Fixed. I'll do a PR with the rest of the Tiled code fixes soon.

screen shot 2016-12-29 at 11 50 02 am
craftworkgames commented 7 years ago

Thanks mate. Looking forward to it :)

lithiumtoast commented 7 years ago

@craftworkgames This can also be closed.

craftworkgames commented 7 years ago

@LithiumToast If you spot any issues that can be closed just close them and leave a comment about why it was closed. We can always reopen them.

lithiumtoast commented 7 years ago

I don't have the permissions.

craftworkgames commented 7 years ago

I don't have the permissions.

Ah right. That makes sense.

I'd seen other people close issues before so I just assumed. Now that I think about it I guess you have permission to close issues that you open.

Looking into it a little further it appears you can only have those fine grained user permissions on Organization accounts.