Created
October 21, 2018 16:06
-
-
Save GaryStanton/3b0a7eba933a9074d1ac55a56acdb988 to your computer and use it in GitHub Desktop.
Phaser 3 utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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