问题
Is there a way to convert a graphic to a sprite? I have a graphic containing a single rectangle, and would like to convert it to a sprite to enable complex animations.
I have tried doing
let p= new Graphics();
p.beginFill(0x000000);
p.lineStyle(0);
p.drawCircle(100, 100, 10);
p.endFill();
const t = RenderTexture.create(p.width, p.height);
renderer.render(p, t);
const sprite = new Sprite(t);
However this is not working.
回答1:
var gr = new PIXI.Graphics();
gr.beginFill(0xFFFFFF);
gr.lineStyle(0);
gr.drawCircle(30, 30, 30);
gr.endFill();
var texture = renderer.generateTexture(gr);
var circle = new PIXI.Sprite(texture);
app.stage.addChild(circle);
来源:https://stackoverflow.com/questions/50940737/how-to-convert-a-graphic-to-a-sprite-in-pixijs