Function to add text inside a class

Hello everyone!

I am trying to integrate a method to my class, whose function is to add text.

However, I am getting an error which I am not able to resolve.

My code:

class Options {

 addText(a,b,c,d){
    a = this.add.text(200,500, a);
    b = this.add.text(370,500, b);
    c = this.add.text(200,550, c);
    d = this.add.text(370,550, d);
 }

}

var example = new Options();

example.addText("Text");

And this is the error I get:
Error

The function individually works correctly, but inside a class it gives me an error.

Thanks!

Add scene parameter.

 addText(scene, a,b,c,d){
    a = scene.add.text(200,500, a);
    b = scene.add.text(370,500, b);
    c = scene.add.text(200,550, c);
    d = scene.add.text(370,550, d);
 }

Then call it

example.addText(this, "Text");
1 Like

That’s interesting.

Thank you, rexrainbow!

omg, I had the exact same problem just now!

this helped me as well @rexrainbow :+1:

and thx for asking @dawser95! :100: