Remove cover overlay from tiles on tilemap

I’m playing around with having hidden/revealed tiles on a map. I remembered that the pxt-tilemaps extension has a feature for covering a tile with another tile’s image, which seemed super handy.

However, it looks like there’s no way to remove a cover from a tile. (Maybe I’m just missing it!) I looked at the source and noticed the cover feature creates a sprite per covered tile with a special kind (SpriteKind._TileSprite). I tried using the array of sprites of kind (to select and destroy them), but that block didn’t include the _TileSprite kind…

Is there any way to destroy tile sprite covers once they’re created?

… also… after seeing the implementation that each tile is covered by a sprite, should I be concerned about the performance of games with moderately sized tilemaps where a high percentage of tiles start out covered? Should I look for an alternate approach to implementing a hidden/revealed tile mechanic?

Great question! We debated whether the special TileSprite kind should be visible to the user or not, and maybe incorrectly decided it shouldn’t be visible (because it is not obvious what it means). We might want to change that to enable situations like this.

If I recall correctly cover sprites are marked as “ghost” so they don’t affect physics checks which should mean you can have lots of them without impacting performance too much.

If you reload a level it should delete all tilesprites I believe, so that might be a work around. Otherwise I you might need to pop into javascript to destroy tile sprites for now…

1 Like

Thanks! That’s helpful.

I thought perhaps the reload trick plus some extra tracking for which tiles were revealed could work, but then I ran into another limitation: currently cover is only provided for covering all tiles of type. It might be nice to also have a way to cover a specific tile at a location.

… oh. I see that block used to be provided but has been disabled because it was too confusing. :cry:

We weren’t sure it would be useful to users, but yours is a great example of where it would be useful! :slight_smile:

I think it’d make sense to re-enable that block and also make the TileSprite kind visible to the user, so I filed some issues:


1 Like