phaser icon indicating copy to clipboard operation
phaser copied to clipboard

DOMElement wrong position

Open TadejZupancic opened this issue 8 years ago • 9 comments

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.

TadejZupancic avatar Aug 08 '18 11:08 TadejZupancic

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.

photonstorm avatar Aug 08 '18 14:08 photonstorm

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.

TadejZupancic avatar Aug 09 '18 09:08 TadejZupancic

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 avatar Aug 10 '18 12:08 TadejZupancic

@TadejZupancic , this.add.dom is released? how can I use it?

charmingny avatar Apr 11 '19 07:04 charmingny

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 avatar Apr 11 '19 08:04 TadejZupancic

@TadejZupancic Is 'add.dom' supported in Phaser 3.16.2?

alexzhao8326 avatar Apr 12 '19 07:04 alexzhao8326

I haven't used it for a while, but I believe it is if you enable the experimental flag and compile it by yourself.

TadejZupancic avatar Apr 12 '19 07:04 TadejZupancic

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.

photonstorm avatar Apr 12 '19 08:04 photonstorm

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.

charmingny avatar Apr 12 '19 13:04 charmingny