Jump to content

Count all tiles by id/property


Recommended Posts


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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