Stacked tilemap optimization

#1

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?

0 Likes

(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

#3

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?

0 Likes

(Jaynus) #4

The Hidden component currently serves that purpose

0 Likes

#5

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

0 Likes

(Gray Olson) #6

You can attach/detach components to entities by using a WriteStorage (see https://docs.rs/specs/0.14.3/specs/type.WriteStorage.html ‘Inserting and Removing Components’) or using a LazyUpdate (https://docs.rs/specs/0.14.3/specs/struct.LazyUpdate.html)

0 Likes