[GUI.Image.source] Why this prop was undefined at GUI.Image?

Founded ‘.source’ was ‘undefined’, And ‘.sourceWidth’ was 0 when always.
I should know source image’s size. this is that for ‘nine patch’.

This is my code

const tempImage = new BGUI.Image('panel', ref );
const tempImageWidth = tempImage.sourceWidth;
const tempImageHeight = tempImage.sourceHeight;
console.log(tempImage.source, ':', tempImageWidth, '/', tempImageHeight);
tempImage.stretch = BGUI.Image.STRETCH_NINE_PATCH;
tempImage.sliceTop = slicePxSize;
tempImage.sliceLeft = slicePxSize;
tempImage.sliceBottom = tempImageHeight - slicePxSize;
tempImage.sliceRight = tempImageWidth - slicePxSize;
tempItem = tempImage;

And this is PG ref : https://www.babylonjs-playground.com/#G5H9IN#10
Point is 53 - 63 lines.

Plz & Thank you! :pray:

Hello
this is because the loading of your image from the url is asynchronous.
You have to wait for the image to be loaded to get the info. Furthermore the property sourceWidth is the width of the image to read from (0 means all): Use the Babylon GUI - Babylon.js Documentation

You want to use domImage.width:
https://www.babylonjs-playground.com/#G5H9IN#11

1 Like

So simple & in a nutshell!
You are awesome!
Thank you! :+1:

1 Like