1. Create custom properties as explained at https://www.youtube.com/watch?v=nCp-EK_IICA
2. Load your scene into Phaser as explained at https://www.youtube.com/watch?v=_QqKMv6I2hc
3. Access your custom properties with levelScene.getBody(name).data.customProperties (not data.m_userData as I expected), which is an array of objects.
Getting the value of a specific property isn't as straightforward as something like data.customProperties.propertyName, so I wrote a function to get the values:
Code: Select all
function getProp(body, key) {
var arr = body.data.customProperties;
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
if (arr[i].name == key) {
console.log(arr[i].int);
return arr[i].int;
}
}
}
Hope someone finds this helpful!