Stacked tilemap optimization


For my game I need a stacked tilemap, that is, each tilemap cell is a stack, where tiles can be put on top of each other. There are two types of tiles; full and partial. Full tiles have no transparency and partial have some transparency.

To optimize this, I may only render the topmost full tile of the stack and any partial tiles above it. However, it is my understanding you can’t put more than one component of each type in an entity, and even if you could, I’m not sure you can add components to an already built entity?

I could make each tile a separate entity and simply make them not render. I see there’s an SpriteVisibility and SpriteVisiblitySortingSystem, but I’m afraid I don’t know how to use it.

Another thing, is it necessary to create a spritesheet for a single texture? Is there a way to use the entire texture without creating additional .ron files?


(Théo Degioanni) #2

Simply use multiple entities that you keep track of for rendering each sprite: one for the highest non-transparent one, and multiple for all transparent ones above it. The sprite visibility sorting is toggled with a method on your DrawFlat2D pass, and it basically orders sprites along their Z value. Don’t forget to add the Transparent component to entities that have to be ordered (this is not ideal and won’t be necessary in the future).

You can simply attach a texture to an entity I believe to have it be rendered without importing a SpriteSheet. Please not however that sharing textures with a SpriteSheet will always be more efficient.

1 Like


Yes, but tiles would effect enemies on top of them, even if they are not rendered, so I need entities for them too. Ideally I want to be able to set_visible(false) or something like that. Is there such a feature?


(Jaynus) #4

The Hidden component currently serves that purpose



But how to attach/detach components to entities at runtime?


(Gray Olson) #6

You can attach/detach components to entities by using a WriteStorage (see ‘Inserting and Removing Components’) or using a LazyUpdate (