Jump to content

Count all tiles by id/property


pros22su
 Share

Recommended Posts

Hi,

I am using the same approach in my game to make items collectible in my game as in this example: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=tile+callbacks.js&t=tile%20callbacks

 

Coins are added to tilemap and tile callback functions are used. Let's say I have a door that will be opened after all coins are collected.

 

Is there a way to count how many coins are on the map using tile ID or tile custom property?

Link to comment
Share on other sites

I had a closer look into and the final result is:

findTilesByProperty: function(property, value, layer) {    var result = [];    layer.layer.data.forEach(function (v) {    	v.forEach(function (tile) {    		if(tile.properties[property] === value) {    			result.push(tile);    		}    	});    });    return result;}
Edited by pros22su
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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