Jump to content

Sprite texture from dynamically rendered SVG?


d13
 Share

Recommended Posts

Hi Everyone!

Just a quick (hopefully!) general question for someone who might have done something like this before. I'm working on a game with lots of speech bubbles. The bubbles can contain a variable amount of text, so they would need to dynamically scale based on how much text they contain. The text also needs to be screen-reader accessible, so it can't be purely embedded in a bitmap. I'm thinking of dynamically rendering the speech bubbles with text as SVG. My question is: can I use the dynamically rendered SVG as a Pixi sprite texture?

Thank you!

 

Link to comment
Share on other sites

Yes, you can.

texture = Texture.from(canvas);

//each time you update canvas

canvas.clearRect();
canvas.drawImage(changedSvg);
texture.update(); 

Also you can embed it into your own SVGResource like that

https://github.com/pixijs/pixi.js/blob/dev/packages/core/src/textures/resources/SVGResource.js

https://pixijs.io/examples/#/textures/gradient-resource.js

Link to comment
Share on other sites

Just now, d13 said:

that's why we dont have any special API's for that in pixi, except SVGResource. Anyone can do that if they know how to upload canvas2d to webgl texture in pixi.

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...