So I have an HTML file in my game assets which I preload and create using
const htmlEl = this.scene.add.dom(0, 0).createFromCache(“HTML asset name from loader”);
Then I add it to the container and show: all the content is visible and as expected.
After creating and before showing I manipulate some of htmlEl children DIVs setting text content and changing the display property. After the manipulation, the resulting content has a different size and I need to recenter it.
- htmlEl.width and htmlEl.height properties contain some old “pre-manipulation” values, but if I call htmlEl.updateSize() these properties become “0”. I am making sure to set htmlEl to be visible and its alpha > 0 before calling updateSize(). So why width and height are zeroes??
- Ok then, I put console.log(htmlEl.node) and get all the properties of the HTMLElement object, and its properties “offsetWidth” and “offsetHeight” have the correct values that I want to use so
- I am accessing htmlEl.node.offsetWidth and htmlEl.node.offsetHeight and get zeroes again (not “undefined” but “0”!). Why zeroes again??
- Ok, console.log(Object.keys(htmlEl.node)) and I get “[‘phaser’]” only - but where did all the HTMLElement properties go??
- checking prototype: console.log(Object.getOwnPropertyNames(Object.getPrototypeOf(htmlEl.node))) - "[‘align’, ‘constructor’] …
I even looked at the source and found that “htmlEl.node.phaser” is a pointer to htmlEl itself, but why?
But how can I get these “offsetWidth” and “offsetHeight” props of htmlEl.node that I see in the console??
Please, help!