[SOLVED] 2D Screen rebuild?

Hi everyone.
I’m having an issue with resizing UI elements from code:
I have hardcoded positions for anchors and margins for and want to switch inbetween on certain events (like growing/shrinking a minimap on click)
The issue is, after setting the anchor and margins for the Element, it doesn’t resize only on window resize…
Is there an equivalent like in Unity, LayoutRebuilder.ForceRebuildLayoutImmediate?

This is a small code snippet:


    if(minimap.percent<0.75 && minimap.triggerGrow){
        minimap.percent+=dt*0.5;

        minimap.uiElement.element.anchor.x=1-minimap.percent;
        minimap.uiElement.element.anchor.y=1-minimap.percent;
        minimap.uiElement.element.anchor.z=minimap.percent;
        minimap.uiElement.element.anchor.w=minimap.percent;
    
        minimap.uiElement.element.margin.x=0;
        minimap.uiElement.element.margin.y=0;
        minimap.uiElement.element.margin.z=0;
        minimap.uiElement.element.margin.w=0;
    }else if(minimap.percent>=0.75 && minimap.triggerGrow){
        minimap.triggerGrow=false;
    }
1 Like

Enabling/disabling the 2DScreen and/or element doesn’t seem to do anything either

It’s private API and it’s not something I’ve done before, maybe you can force it by doing the same thing as resize() callback does here?

1 Like

Keeping copy in init of the initial resolution and re-applying it works :slight_smile:

Minimap.prototype.initialize = function() {
minimap.referenceResolution=minimap.screen2D.screen.referenceResolution;
};
Minimap.prototype.update=function(dt){
//...
minimap.screen2D.screen.referenceResolution=minimap.referenceResolution;
};

on every frame while it’s resizing and works just fine.

Thanks, @yaustar

Thats a quite usefull information :+1:
I’ve tried so hard make a UI-button blink to give the player some oriantation
with scale() and it never worked. So ended up in changing color, translate for and back
or point an arrow to it. Now everything makes sense again… thanx :cucumber: