A very noobiish question is coming. I stuck here with ImageFill module.
I want to fill a square with grabbed image. I managed to grab the image and fill it in the square dynamically, but cannot figure out how to use the imageFill.scaleBehavior.
In the typings repo, I found this line, which suggests to use cloneWithOverrides but can’t wrap my head around as I cant find it in documentation.
Any help regarding this issue will be appreciated.
I think (though I just copied and pasted the docs during the Beta when I did these typings ) that this means you can’t just change this property in an ImageFill of a node like
node.fill.scaleBehaviour = ImageFill.SCALE_COVER;
but you have to reassign it like
let fill = node.fill.clone();
fill.scaleBehaviour = ImageFill.SCALE_COVER;
node.fill = fill;
There were some quirks with image fills in the beta versions of extensibility, but in the actual shipping APIs it’s as simple as:
let fill = node.fill;
fill.scaleBehavior = ImageFill.SCALE_COVER;
node.fill = fill;
That is, there’s no need to clone it (and there’s no “cloneWithOverrides” API anymore).
You do still need to re-invoke the fill property setter though, so you can’t just set node.fill.scaleBehavior = ... inline. That caveat is true of any scenegraph property whose value is an object – see " Properties with object values" in the docs.
Note that SCALE_COVER is the default, so there’s often no need to run the exact code shown above though…