好吧,我想出了一个办法,其实很简单。
只需将图形对象作为从html画布创建的精灵的掩码。
function setup() {
var can2 = document.getElementById('can2');
var sprite = new Sprite(PIXI.Texture.fromCanvas(can2))
var graphics = new PIXI.Graphics();
graphics.beginFill();
graphics.drawCircle(300, 300, 200);
graphics.endFill();
sprite.mask = graphics;
stage.addChild(sprite);
renderer.render(stage);
}
此外,作为精灵的子对象添加图形是最好的方式,只需要确保它们的尺寸相同。完成后,我可以自由移动精灵,它的渐变纹理不会改变,或者更准确地说,它会随着精灵移动。当然,一切都必须在维度上相等。
var graphics = new PIXI.Graphics();
graphics.beginFill();
graphics.drawCircle(100, 100, 100);
graphics.endFill();
sprite.addChild(graphics);
sprite.mask = graphics;