Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated tile IDs, and nullptr returned by tileset->getTile(tileId), local vs global #110

Closed
Moros1138 opened this issue Nov 27, 2023 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@Moros1138
Copy link

uint32_t ownerId = tileObject.getTile()->getId();

This fails to account for the idea of multiple tilesets in a single map. I just spent the last 3 hours (or so) trying to figure out why my animatedTile was always nullptr

To save others from the same frustration here's what works for me. I had to modify the animation code in my own project in this way, but I figured I'd use the examples because it's how people are learning to use Tileson.

            uint32_t ownerId = tileObject.getTile()->getId() + tileset->getFirstgid() - 1;  // HERE
            if(m_animationUpdateQueue.count(ownerId) == 0) //This is only built once to track all tile IDs with animations
                m_animationUpdateQueue[ownerId] = &tileObject.getTile()->getAnimation();

            uint32_t tileId = tileObject.getTile()->getAnimation().getCurrentTileId() + tileset->getFirstgid() -1; // AND HERE...
            tson::Tile *animatedTile = tileset->getTile(tileId);
            drawingRect = animatedTile->getDrawingRect();

I don't know that this is indicative of a problem with Tileson and the way it handles Ids, but I wanted to share this so hopefully others don't befall my fate.

@SSBMTonberry
Copy link
Owner

SSBMTonberry commented Nov 29, 2023

Thank you for posting this, @Moros1138 🙂
I recon the animation part of the examples is pretty old, so there might be some things it does not consider, and should be taken with a grain of salt. At the same time, this seems like an issue that Tileson should be able to solve for you, or at least make more easy or straight forward to resolve. I'll put this into the current roadmap. I'm sure something can be done to make this more intuitive and easy to use! The idea behind a lot of the features exclusive to Tileson is to make it as easy as possible to use a Tiled map without having to deal with unnecessary manual mappings that can be done beforehand 😄

Edit:
To make this clear: The issue itself is not a bug per se, but rather that Tileson uses data directly from Tiled (more or less) without providing anything to make it intuitive with several tilesets containing animations. The reason for this is that I've simply not thought about this in the implementation, and no one has reeported this previously. This goes to show how important it is to report issues like this - so Tileson can become better 🙂

@SSBMTonberry SSBMTonberry added the bug Something isn't working label Nov 29, 2023
@SSBMTonberry SSBMTonberry added this to the Version 1.5.0 milestone Nov 29, 2023
@Moros1138
Copy link
Author

First, you're very welcome. Regarding the bug label. I, myself, wasn't particularly comfortable with calling it a bug when I was crafting the issue/post. I opted to approach it from the "it might save someone else some hassle" kinda post!

If I might briefly indulge in non sequitur. It's been great being able to integrate Tiled maps into my own projects. Originally I rawdogged JSON parsing and doing it all myself. Then I found out you already suffered for me! Thanks for Tileson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants