Yes, you can change the prototype of text creation if you want to keep the API style.
const prototypeText = Phaser.GameObjects.GameObjectFactory.prototype.text
Phaser.GameObjects.GameObjectFactory.prototype.text = function (x, y, text, style = { font: '30px fantasy' }) {
return prototypeText.call(this, x, y, text, style);
}
let myText = this.add.text(100, 100, "Hello, Qugurun!");
You can also make your class inheriting from the text and prescribe the necessary default parameters inside the class.
//text.js
export class Text extends Phaser.GameObjects.Text{
constructor(scene, x, y, text, style = { font: '30px fantasy' }) {
super(scene, x, y, text, style);
scene.add.existing(this);
}
}
//other js
import { Text } from "text.js";
... other code
let myText = new Text(this, 100, 200, "Hello, Qugurun!");
you can wrap everything in your text creation function, which will also set default parameters and return ready-made the object.
//text.js
export function newText (scene, x, y, text, style = { font: '96px arial' }){
return scene.add.text(x, y, text, style);
}
//other js
import { newText } from "text.js";
... other code
let myText = newText(this, 100, 300, "Hello, Qugurun!");