Jump to content

How to make a circle shape Sprite in PIXI v4?


caymanbruce
 Share

Recommended Posts

It seems I can't make a circle shape sprite directly using new Sprite. Can I create a new sprite with a texture generated from a Graphics object which is a circle?

For example, I want to create a circle shape sprite. Can I write this?

 

       const p = new Graphics();
        p.beginFill(0x000000);
        p.lineStyle(0);
        p.drawCircle(100, 100, 10);
        p.endFill();
        let sprite = new Sprite(p.generateCanvasTexture());

Link to comment
Share on other sites

11 hours ago, khalim said:

I have found that I can render the graphics into a texture, using RenderTexture, like this:

 

const 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);
sprite.x = 100;

This way I can render a circle shape sprite.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...