Vexen Crabtree Posted June 29, 2018 Share Posted June 29, 2018 I want to adjust the alpha of all tiles of a particular type, but I don't know an elegant way of doing it... I could iterate through all tiles, and find them one by one. Is there a cleverer way? Something like a "get_tilesByType" function, used like this: levelData.tilemap.get_tilesByType(11).setAlpha(0.7); (or iterating through each returned object and running .setAlpha). As the player runs around, they clean up 'dirt' (tile index = 11 from the tilemap). How do I count how many dirts remain? It is likely a similar solution to the one above; var dirt_remaining = levelData.tilemap.get_tilesByType(11).length; If you're interested, this is how I'm cleaning dirt tiles: levelData.tilemap.setTileIndexCallback(11,cleanDirt,this); function cleanDirt(pPlayer,pTile) //Has to accept pPlayer because this is invoked by a game collide callback levelData.tilemap.fill(-1,pTile.x,pTile.y,1,1); dirtCleanedQ+=1; txtComplete.setText("Cleanliness:\n " + Math.floor(100*dirtCleanedQ/dirtStartQ) + "%"); }; Link to comment Share on other sites More sharing options...
Vexen Crabtree Posted June 29, 2018 Author Share Posted June 29, 2018 filterTiles(callback [, context] [, tileX] [, tileY] [, width] [, height] [, filteringOptions]) appears to be the solution (testing it now), if so I'll delete this thread... Link to comment Share on other sites More sharing options...
Vexen Crabtree Posted June 29, 2018 Author Share Posted June 29, 2018 .filterTiles doesn't have a "by index type" filter option, so here's the code I've ended up with: levelData.dirtStartQ=0; levelData.tilemap.forEachTile(function(pTile){ if(pTile.index==11){ levelData.dirtStartQ++; pTile.setAlpha(0.7) }; }); Link to comment Share on other sites More sharing options...
Recommended Posts