6

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.

gman
  • 100,619
  • 31
  • 269
  • 393
21rw
  • 1,016
  • 1
  • 12
  • 26

1 Answers1

13
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);
Aivaras
  • 156
  • 3
  • 7