这是我用来插入它的代码。它与我从Codepen示例中抢夺的地图一起使用时效果很好,但是当我创建自己的.png(稍微大一点)时,带有原始图像的屏幕空间就会出现,并且置换图会变成黑色。我在做什么错了?
const createRipple = () => {
const sprite = new PIXI.Sprite(PIXI.loader.resources['map2.png'].texture);
sprite.anchor.set(0.5);
sprite.scale.set(2);
stage.addChild(sprite);
const filter = new PIXI.filters.DisplacementFilter(sprite);
stage.filters = [filter];
return {
update: () => {
const mouse = renderer.plugins.interaction.mouse.global;
sprite.position.x = mouse.x;
sprite.position.y = mouse.y;
// center canvas inside #main
$('canvas').css('margin-left', ($('#main').width() - $('canvas').width())/2)
}
};
};