i am pulling my hair out trying to figure out how to add a simple property to a sprite/container so that i can identify it when it’s clicked. This is what makes sense to me simply but doesn’t seem to work.
this.sprt = this.add.sprite(100,100,‘key’);
this.sprt.id = ‘your sprite’;
this.sprt.on(‘pointerup’, function(this.sprt){
console.log(this.sprt.id);
}
Click and then ‘your sprite’ in the log. Please tell me what i am missing.
Hi @bigmartizzle and wellcome,
The listener receives the pointer and has as context the object, so:
this.sprt.on('pointerup', function (pointer) {
console.log(this.id);
});
Greetings.
Worked like gang busters!
Much appreciation!