Jump to content

List of clickable text rows with different actions


markus.n
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...