Sign in to follow this  
caymanbruce

How to make a circle shape Sprite in PIXI v4?

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());

Share this post


Link to post
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.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.