With that done your IDE of choice (if you use one that is) should be having an issue with the BuildMapTiles function because we have not yet updated the return parameter when we call our newly updated BuildSheetData function. We’ll fix that now.
- We loop through the tilesets in reverse order as the tilesets are added with the tile ids in ascending order.
- If the tile id is greater than or equal to the key we know that the tile belongs to this tileset as we are iterating over the tileset in reverse order.
- If no tileset is found we skip this tile. This should not happen and we will want to add additional logging here.
And that’s it for our parser! We can now use multiple tilesets however if you run the game you will probably not see the new layer. This is because we have not created a method of drawing sprites in a certain order as currently they are drawn in the order we add them to the object collection.
To accomplish this we’ll need to create a drawable component and a drawable system. As you’ll remember from previous tutorials, a component is what we use to extend objects functionality and a system will control the components. This is the beginning of a conversion to a true Entity Component System model that we discussed here. Although we’re not converting completely (yet) as components in an ECS are purely data objects and our components will still do some processing i.e. drawing the sprites.
- We currently do not support layers. It would be good if we could set a group of sprites as a background layer for example and have them always drawn before subsequent layers.
- We are drawing everything regardless of whether it is onscreen to not. We should add Occlusion Culling.
- We have a limit of one drawable per object. In future, we will want to add more.
- If we add a new drawable component to an object the drawable system will not sort its collection to accommodate the new object, consequently, it is likely that the object will be drawn out of order.