DOMElement wrong position
DOMElement's size is not recalculated if the contents change, which leads to wrong position on the screen.
var div = document.createElement('div'); div.style = 'font: 48px Arial; font-weight: bold; color: white'; //div.innerText = 'Phaser 3'; element = this.add.dom(400, 300, div); element.setText('Phaser 3');
Text should be displayed as if the commented line was uncommented.
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.
I've tested it and it still doesn't work. getBoundingClientRect() returns all zeros. Looks like it takes some time before it gets set, because later it shows correct values.
In my case I had the visibility of the DOMElement set to false and made it visible after setting the text. In that case getBoundingClientRect() returns all zeros. Setting the display to block and then back to none after computing getBoundingClientRect() might flash the element. Maybe the size could be recomputed when the element becomes visible again?
@TadejZupancic , this.add.dom is released? how can I use it?
It was experimental for a long time, but I think it won't be anymore in the next version. The renderer was simple and as far as I remember did not yet compute correct position if it was inside a container. Maybe @photonstorm can tell something about the current status/future plans.
@TadejZupancic Is 'add.dom' supported in Phaser 3.16.2?
I haven't used it for a while, but I believe it is if you enable the experimental flag and compile it by yourself.
It's not in 3.16 unless you build a copy with the experimental flag turned on. However, it's fully in 3.17 (the master branch here) and integrated with the Scale Manager. So will be released properly in this version.
yayyy!!! I was halfway through writing my own one for my game. but now I think I will just wait 3.17 and do other things first for now.