Hey all,
I have successfully managed to migrate a mathematical project from Phaser 2 to Phaser 3. I have deleted ~2 thousand lines of code (from keyboard, events, emitters, setOrigin, containers etc…) and everything* looks and performs so much better.
However*, for every node / circle object, I need to create 2 text objects - an ownerLabel and payoffsLabel. In Phaser 2, this method takes ~0.5ms. In Phaser 3 it takes ~10ms.
This really builds up as every line also has a label. So creating 16 nodes also creates 15 lines which results in ~30 texts and requires ~300ms on Phaser 3 vs ~15ms on Phaser 2. I can add profiling
Code (simplified):
private createLabels() {
this.ownerLabel = this.scene.add.text(0,0, 'some text', {
fontSize: 24,
color: '#000',
fontStyle: 'bold',
fontFamily: 'Arial',
});
this.ownerLabel.setInteractive();
this.payoffsLabel = this.scene.add.text(0, 0, 'some text', {
fontSize: 24,
fontStyle: 'bold',
align: 'right',
fontFamily: 'Arial',
color: '#000'
}).setOrigin(0.5, 0);
this.payoffsLabel.setInteractive();
//"this" points to the node object, which is a container.
this.add([this.payoffsLabel, this.ownerLabel]);
}
P2 version here
P3 version here
You can drag-select the leaves and press “N”, which will generate new nodes.
My thoughts:
- Object Pools? - my objects are fairly complex, with lots properties - both GameObjects and Model Objects, so I would have to create something custom pool which would take a lot of time.
- Bitmap Fonts? - will they be faster? Seems an overkill for an Arial font. Also, if in the future there is a requirement to change fonts, I would have to load each separately. Doesn’t seem like a good idea.
- RenderTexture? - tried it to no avail and also seems like an overkill.
- Disable rendering on creation? I have not tried this, but I do not think it will work…
…
I am really asking for your help on this, because I love Phaser 3 and would really like to stick with it for the future development of the project. Thanks in advance for your help!