Tilemap is empty

0 favourites
  • 8 posts
From the Asset Store
Enchanted Forest & Cave 16x16 Tilemap with Environment Sprites
  • Hi, I would like to know how do I detect when a tilemap is empty without even a block, I need to do this to then delete the empty tilemap

  • Two options:

    1. Loop through all tiles and check if they are empty.

    2. Get Tilemap.TilesJSON of an empty tilemap and save it to a variable. When you need to check if a tilemap is empty, compare its TilesJSON with that string saved in the variable.

    For example, the JSON of an empty tilemap may look like this:

    {"c2tilemap":true,"width":53,"height":30,"data":"1590x-1"}
    

    But in your case it may be different.

  • Two options:

    1. Loop through all tiles and check if they are empty.

    2. Get Tilemap.TilesJSON of an empty tilemap and save it to a variable. When you need to check if a tilemap is empty, compare its TilesJSON with that string saved in the variable.

    For example, the JSON of an empty tilemap may look like this:

    > {"c2tilemap":true,"width":53,"height":30,"data":"1590x-1"}
    

    But in your case it may be different.

    Thanks for the help, I'll stick with option 1, as my tilemap is custom-sized and modified in real-time

  • Two options:

    1. Loop through all tiles and check if they are empty.

    2. Get Tilemap.TilesJSON of an empty tilemap and save it to a variable. When you need to check if a tilemap is empty, compare its TilesJSON with that string saved in the variable.

    For example, the JSON of an empty tilemap may look like this:

    > {"c2tilemap":true,"width":53,"height":30,"data":"1590x-1"}
    

    But in your case it may be different.

    Hey

    I made the code to detect if the TielMap is empty and then delete the TileMap but for some reason if the TileMap is all complete and missing some tile in some frame then it is destroyed, I need it to detect if the tilemap is completely empty to then destroy it

    This is the code I'm using to detect if the TileMap is completely empty

    + System: for "y" to 0 a floor(TileMap.Height÷16)-1 + System: for "x" to 0 a floor(TileMap.width÷16)-1 + TileMap: tile (loopindex("x"), loopindex("y")) = -1 -> TilesMap: Destroy
    
  • You should do something like this:

    Variable isEmpty=1
    
    for "y" to 0 a floor(TileMap.Height÷16)-1 
    for "x" to 0 a floor(TileMap.width÷16)-1 
     TileMap: tile (loopindex("x"), loopindex("y")) >=0 
     ..... Set isEmpty to 0
     ..... Stop Loop
     ..... Stop Loop
    
    
    Compare variable isEmpty=1 
    ...... Tilemap destroy
    
    
    
  • You should do something like this:

    > Variable isEmpty=1
    
    for "y" to 0 a floor(TileMap.Height÷16)-1 
    for "x" to 0 a floor(TileMap.width÷16)-1 
    TileMap: tile (loopindex("x"), loopindex("y")) >=0 
    ..... Set isEmpty to 0
    ..... Stop Loop
    ..... Stop Loop
    
    
    Compare variable isEmpty=1 
    ...... Tilemap destroy
    
    
    

    Sorry it still doesn't work, when I click on a tile to delete it the tilemap is destroyed completely, please when you have some time could you make a cp3

    + touch: to click TileMap
    -> TileMap: arease tile (TileMap.PosTileX(touch.X), TileMap.PosTileY(touch.Y))
    + System: for "y" to 0 a floor(TileMap.height÷16)-1
    + System: for "x" to 0 a floor(TileMap.width÷16)-1
    + System: TileMap.TileAt(loopindex("x"),loopindex("y")) = 0
    ----+ System: isEmpty = 1
    -----> TileMap: destroy
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • howtoconstructdemos.com/roller-paint-demo

    Thank you very much

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)