easeljs 背景图像矩形 - 封面

easeljs background image rect - cover

我在 easeljs 中有一个形状。最初创建时,它的背景颜色设置为白色。然后,在稍后的某个时候,我需要给这个矩形形状一个背景图像 - 我真的无法让它工作。

我希望形状的背景图片定位如下:

background-image:    url(images/background.svg);
background-size:     cover;                   
background-repeat:   no-repeat;
background-position: center center;

任何人都可以告诉我如何处理这个问题。谢谢:)

如果你想在 EaselJS 中使用背景图片,你不能使用 CSS。

您可以改用 bitmapFill 和 EaselJS 图形,它使用图像进行图案填充。

var img = document.createElement("img");
img.src = "path/to/image";

var shape = new createjs.Shape();
shape.graphics.beginBitmapFill(img, "optionalRepeat", optionalMatrix);
shape.graphics.drawRect(0,0,100,100);

这里是一个快速的 fiddle 展示它的实际效果:http://jsfiddle.net/lannymcnie/ogy1qmxn/2/

干杯,