如何在 pixi.js 多边形上放置纹理?
How put a texture on pixi.js polygon?
我可以在 pixi.js 中用纹理填充多边形吗?
我需要用点创建一个多边形并用纹理填充它。我该怎么做?
感谢您的帮助!
我认为您不能用纹理填充多边形,但您可以将多边形用作 Sprite 的蒙版,这会产生相同的效果。这样的事情会起作用:
var stage = new PIXI.Stage(0, true);
var renderer = PIXI.autoDetectRenderer(620, 380);
document.body.appendChild(renderer.view);
//create a texture
var texture = PIXI.Texture.fromImage("/img/logo.png");
var tilingSprite = new PIXI.TilingSprite(texture, 620, 380);
stage.addChild(tilingSprite);
//create a polygon
var graphics = new PIXI.Graphics();
graphics.beginFill(0);
graphics.moveTo(50,50);
graphics.lineTo(300,140);
graphics.lineTo(220, 320);
graphics.lineTo(80, 110);
graphics.lineTo(50,50);
graphics.endFill();
stage.addChild(graphics);
//mask the texture with the polygon
tilingSprite.mask = graphics;
update();
function update()
{
requestAnimFrame( update );
renderer.render(stage);
}
jsfiddle: http://jsfiddle.net/7asnhk3b/
我可以在 pixi.js 中用纹理填充多边形吗?
我需要用点创建一个多边形并用纹理填充它。我该怎么做?
感谢您的帮助!
我认为您不能用纹理填充多边形,但您可以将多边形用作 Sprite 的蒙版,这会产生相同的效果。这样的事情会起作用:
var stage = new PIXI.Stage(0, true);
var renderer = PIXI.autoDetectRenderer(620, 380);
document.body.appendChild(renderer.view);
//create a texture
var texture = PIXI.Texture.fromImage("/img/logo.png");
var tilingSprite = new PIXI.TilingSprite(texture, 620, 380);
stage.addChild(tilingSprite);
//create a polygon
var graphics = new PIXI.Graphics();
graphics.beginFill(0);
graphics.moveTo(50,50);
graphics.lineTo(300,140);
graphics.lineTo(220, 320);
graphics.lineTo(80, 110);
graphics.lineTo(50,50);
graphics.endFill();
stage.addChild(graphics);
//mask the texture with the polygon
tilingSprite.mask = graphics;
update();
function update()
{
requestAnimFrame( update );
renderer.render(stage);
}
jsfiddle: http://jsfiddle.net/7asnhk3b/