How to convert a graphic to a sprite in pixijs

▼魔方 西西 提交于 2021-02-10 06:15:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!