Skip to content

Instantly share code, notes, and snippets.

@GaryStanton
Created October 21, 2018 16:06
Show Gist options
  • Save GaryStanton/3b0a7eba933a9074d1ac55a56acdb988 to your computer and use it in GitHub Desktop.
Save GaryStanton/3b0a7eba933a9074d1ac55a56acdb988 to your computer and use it in GitHub Desktop.
Phaser 3 utils
/*
Phaser 3 utility functions
Author: Gary Stanton
*/
/**
* Get GID from a tileset by property and value
* @param {Phaser.Tilemaps.Tileset} tileset - A Phaser Tileset object
* @param {string} name - The name of the property to inspect
* @param {string} value - The value of the property to match
* @return {number} The tile GID
*/
export function getTileGIDByProperty(tileset, name, value) {
let tileGID = 0;
Object.values(tileset.tileProperties).forEach((prop, i) => {
if (prop[name] === value){
tileGID = tileset.firstgid + i;
}
});
return tileGID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment