markus.n Posted April 1, 2014 Share Posted April 1, 2014 Hi, How should I create a list of text objects, which do different things when clicked? In my case, it's about choosing dialogue and whatever happens next.for (var i = 0; i < this.textChoice.length; i++) { this.textArray[i] = this.game.add.text(this.game.world.centerX, 150 + i * 20, this.textChoice[i].text); this.textArray[i].inputEnabled = true; this.textArray[i].events.onInputDown.add(function() { this.dialogueNext(WHATHERE?); }, this);}What should I put as a parameter for the dialogueNext function? It'd need this.textChoice.id in order to define the next action. If I use the i variable, it's either undefined or the last value of it when it gets clicked. A great thank you for anyone willing to help me.(edit: solved a part of the problem) Link to comment Share on other sites More sharing options...
rich Posted April 1, 2014 Share Posted April 1, 2014 The onInputDown callback receives 2 parameters - the sprite (or object) that caused the event, and the pointer that triggered it. So in your case you could do something like this maybe:for (var i = 0; i < this.textChoice.length; i++) { this.textArray[i] = this.game.add.text(this.game.world.centerX, 150 + i * 20, this.textChoice[i].text); this.textArray[i].name = 'text' + i; this.textArray[i].inputEnabled = true; this.textArray[i].events.onInputDown.add(this.dialogueNext, this);}function dialogueNext(text, pointer) { if (text.name === 'text1') { // do stuff, etc }} Link to comment Share on other sites More sharing options...
markus.n Posted April 1, 2014 Author Share Posted April 1, 2014 Wow, thanks! Didn't even cross my mind to check parameters without sending any parameters. In the end this was much easier than I thought. Link to comment Share on other sites More sharing options...
Recommended Posts