Are there any implications for tiles that are outside the tilemap?

0 favourites
  • 11 posts
From the Asset Store
Piano tiles
$9.99 USD
Template for a piano tiles game, fully documented in comments and video
  • I've wondered this for a while. If you take a tilemap, draw a bunch of tiles and then scale the tilemap smaller, the tiles visually disappear. If you scale it back up they reappear, so they are clearly not deleted. But does it mean they use up any kind of space or processing? As in: Should I always make sure to delete them or is it basically irrelevant?

  • I tested with 1000 tilemaps created on every tick and apart from a slightly higher memory usage there's no difference in performance.

    The funny thing is that you can't actually delete those invisible tiles, even if you erase them, they are still stored in timemap data. The only way to shrink the tilemap is to delete all instances of it, restart the editor, create a small blank layout (say, 300x300 px) and place the tilemap object on it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Or, if you are comfortable with editing project files, here is a little tool I made that converts tilemap data to a string that can be stored in Layout.json file. It also shrinks the tilemap. It can be useful if you create tilemaps in runtime and want to store them permanently in the project.

    dropbox.com/scl/fi/mda3f73tgpbmnjmv5ofde/tilemap_data_convert.c3p

  • My understanding is that your entire tilemap bitmap is loaded and stored in memory, if it is on the layout, regardless if the tiles are used or not. Rendering wise if they're invisible, you're not drawing them, and thus should take no additional resources. If it drawn, you'll have your usual fill rate considerations (which normally wouldn't need to be considered at all, unless you're putting layers of layers of stuff with force own texture stacked on top of each other within a single viewport for some reason). Similarly, tiles outside the viewport should not be drawn as well for obvious reasons.

  • When you draw a tile, a model is created to represent it, it mainly has the position and the index of the tile. Those models are never actually deleted after creating them because it is infinitely easier to keep them around than figure out what needs to be recreated and with what information depending on what changes.

    Since the tile models don't hold any image data themselves they are rather lightweight memory wise. They could probably be made to be more compact if they where represented in some unorthodox way (thinking about storing all the information directly in an ArrayBuffer instead of a class so all the bits can be packed as neatly as possible and using static methods instead of class methods to reduce the memory footprint even further), I don't think it's worth the trouble though.

    When it comes to drawing, only the visible tiles are looked at, so that part is as efficient as it can be.

  • Thanks for the answers. It's just that I duplicate a bunch of tilemap objects across my layouts and I sometimes stumble upon random assortment of tiles outside of the actually used area when I have to scale the map bigger. But considering even deleting them doesn't exactly do anything I might skip deleting it (but my brain hates it that I know they are there :V)

  • This is a really informative thread! Like WackyToaster, I use a lot of tilemaps to create layered background objects.

    If I can ask a clarifying question based on dop2000's comment and tool — if the layout size is 1000x1000, does this mean that every tilemap object added contains tile data for 1000x1000, even if the object is resized to 50x50?

    Curiousity only — it sounds like it doesn't matter memory-wise even if so!

  • if the layout size is 1000x1000, does this mean that every tilemap object added contains tile data for 1000x1000, even if the object is resized to 50x50?

    I think so. When you add a new tilemap, its size is set to layout size. If you resize the tilemap, it will still remember its initial size and will store the values for those invisible tiles.

  • Ah ok! Thanks! I've been curious about how tilemaps work under the hood. There are some ideas for feature requests I have, like being able to shift the tiles left/right/up/down within the map, but I don't know enough (yet) about how this works to make the request.

    Thank you for the tool above as well!

  • I don't think so actually, Diego did say "when you draw a tile", so if your tilemap is empty (no tiles drawn/added) presumably all those empty tiles (note that tile 0 is not "empty") by default wouldn't need to be considered or have an overhead.

    Regardless, as you mentioned, it wouldn't have much of a memory impact even if it did, relative to image/sprite data.

  • Here is what happens when I add a blank tilemap, immediately resize it to 10x10 tiles, then draw some tiles on it.

    "tilemapData": {
    "width": 10,
    "height": 10,
    "max-width": 53,
    "max-height": 30,
    "data": "9x0,5,29x0,5,29x0,5,29x0,5,29x0,5,29x0,5,29x0,5,29x0,5,29x0,5,29x0,5,1310x0"}
    

    As you can see, Construct remembers the initial size and stores lots of zeros for tiles which are beyond the 10x10 area. (Here tile indices start with 1, and 0 is an empty tile. For example "29x0" means 29 empty tiles.)

    Of course, it's a negligible overhead - just a few extra bytes of data and perhaps an extra microsecond to parse them. But if you have lots of tilemaps in your game, it may be a good idea to create them with the correct size from the beginning:

    "tilemapData": {
    "width": 10, 
    "height": 10, 
    "max-width": 10, 
    "max-height": 10, 
    "data": "9x0,5,9x0,5,9x0,5,9x0,5,9x0,5,9x0,5,9x0,5,9x0,5,9x0,5,9x0,5"}
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)