Tilengine - The 2D retro graphics engine forum
Remove tile from tilemap - Printable Version

+- Tilengine - The 2D retro graphics engine forum (http://tilengine.org/forum)
+-- Forum: English forums (http://tilengine.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (http://tilengine.org/forum/forumdisplay.php?fid=7)
+--- Thread: Remove tile from tilemap (/showthread.php?tid=577)



Remove tile from tilemap - mycats - 05-13-2020

Hi! I am trying to remove tile from tilemap (for ring collision) with this code:
Code:
if(ring_found)
{
    PlaySoundId(7);
    TLN_SetTilemapTile(foreground_tilemap,tileinfo.row,tileinfo.col,TLN_Tile(0));
    TLN_SetLayer(LAYER_FOREGROUND,NULL,foreground_tilemap);
    rings++;
}
But it gives Invalid Pallete reference when running SetLayer(). Any solution?


RE: Remove tile from tilemap - megamarc - 05-13-2020

Are you using the same assets you posted some days ago?

It's not needed to reconfigure layer with TLN_SetLayer() once you modify the tilemap with TLN_SetTilemapTile(), they're already linked.


RE: Remove tile from tilemap - mycats - 05-14-2020

Removed SetLayer(), still not removing tile. But no more errors in log.


RE: Remove tile from tilemap - megamarc - 05-14-2020

Are you passing the correct row and column? The following code works for me, when I press input 1, it removes the first ring:

Code:
    while (TLN_ProcessWindow()) {
        if (TLN_GetInput(INPUT_BUTTON1)) {
            Tile tile = {0};
            TLN_SetTilemapTile(foreground_tilemap, 54, 6, &tile);
        }
        TLN_DrawFrame(0);
    }



RE: Remove tile from tilemap - mycats - 05-14-2020

Thanks! You need to define empty tile before setting it and use
Code:
Tile tile={0};
TLN_SetTilemapTile(foreground_tilemap,tileinfo.row,tileinfo.col,&tile);
instead of
Code:
TLN_SetTilemapTile(foreground_tilemap,tileinfo.row,tileinfo.col,NULL);



RE: Remove tile from tilemap - megamarc - 05-14-2020

Welcome!

I understand the confusion, it seems more intuitive to delete a tile passing just NULL instead of a valid pointer with index 0, right? I'll add this behavior in next update