d13 Posted October 24, 2019 Share Posted October 24, 2019 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! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 24, 2019 Share Posted October 24, 2019 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 Quote Link to comment Share on other sites More sharing options...
d13 Posted October 24, 2019 Author Share Posted October 24, 2019 Thanks Ivan! I need to use the SVG as a texture source for a sprite.. is that possible using those methods? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 24, 2019 Share Posted October 24, 2019 There's no escape. The only way is through canvas Quote Link to comment Share on other sites More sharing options...
d13 Posted October 24, 2019 Author Share Posted October 24, 2019 Thanks! So, I guess my next question... is it possible to render a dynamic created SVG onto a canvas? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 24, 2019 Share Posted October 24, 2019 pass an svg element in drawImage. Quote Link to comment Share on other sites More sharing options...
d13 Posted October 24, 2019 Author Share Posted October 24, 2019 Nice, I didn't know that! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 24, 2019 Share Posted October 24, 2019 (edited) Just for your knowledge - that's the only way using browser api to pass it to webgl. Manual, "parse it with js" solutions like https://github.com/exponenta/pixi5-svg have serious limitations. Edited October 24, 2019 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
d13 Posted October 24, 2019 Author Share Posted October 24, 2019 This seems to be a simple example... https://stackoverflow.com/questions/3768565/drawing-an-svg-file-on-a-html5-canvas Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 24, 2019 Share Posted October 24, 2019 Just now, d13 said: This seems to be a simple example... https://stackoverflow.com/questions/3768565/drawing-an-svg-file-on-a-html5-canvas 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.