How to change a Button's Image

Tried a few things, but nothing is working, yet.

    var Button2 = Button.CreateImageOnlyButton("", "static/play.svg");
    Button2.thickness = 0;
    Button2.width = 0.2; 
    Button2.height = 0.1;
    Button2.left = -100;
    Button2.top = 100;
    Button2.onPointerClickObservable.add(() => {
        Button2.image.diffuseTexture = new Texture("static/red.svg");
    });
    TexturePlane.addControl(Button2);

Thank’s

It’s because you have to use image.source :slight_smile: https://playground.babylonjs.com/#PLTRBV#18

2 Likes

Yep, that worked. Thank’s, it should be added to the “alert button” playground doc link.

const ButtonStart = () => {
    var Button2 = Button.CreateImageOnlyButton("", "static/play.svg");
    Button2.thickness = 0;
    Button2.width = 0.2; //image 200x100px use svg
    Button2.height = 0.1;
    Button2.left = -100;
    Button2.top = 100;
    Button2.onPointerClickObservable.add(() => {
        Button2.image.source = "static/red.svg";
    });
    TexturePlane.addControl(Button2);
};
ButtonStart();