Add and remove Gui image


#1

Hello guys , please i need to open an image when i click in the first time a button , and close the image when i click in the same button a second time , i try it with this code but i know it is wrong , can someone help me ?

var button1 = BABYLON.GUI.Button.CreateImageOnlyButton(bt, “bt.png”);
var test =0;
button1.onPointerUpObservable.add(function() {
test =1;
if (test==1) { advancedTexture.addControl(plan_image); }
if (test==0) {advancedTexture.RemoveControl(plan_image); test=1;}
}
);

advancedTexture.addControl(button1);
advancedTexture.addControl(plan_image);

Thanks


#2

Well your code was a bit off :slight_smile:

you set test to 1 on each call so the image was never removed. Also test was not reset to 0 when it was 1.

Here is a working version:
https://www.babylonjs-playground.com/#X54BNH


#3

Thanks my friend it is working , and i am wondering if there is any function in babylon like “.onPointerUpObservable.” wich allow us to switch beetwen two status without using a “test variable” ?


#4

Unfortunately no but this is not a big constraint :smiley: