Jump to content

Returning all tiles of a specific type


Vexen Crabtree
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...