soylomass Posted August 16, 2019 Share Posted August 16, 2019 Hi, is it possible to copy a Graphics content into another Graphics? I saw there is a clone method, but I don't want to create a new instance, I want to copy its contents into an existing Graphics. Thanks. ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
lmfielding Posted August 16, 2019 Share Posted August 16, 2019 Clone is the best you are going to get unless you copy the properties you want programmatically. May I ask why you don't want to create a new instance?https://pixijs.download/dev/docs/PIXI.Graphics.html#clone Quote Link to comment Share on other sites More sharing options...
soylomass Posted August 16, 2019 Author Share Posted August 16, 2019 1 minute ago, lmfielding said: Clone is the best you are going to get unless you copy the properties you want programmatically. May I ask why you don't want to create a new instance?https://pixijs.download/dev/docs/PIXI.Graphics.html#clone Because I want to do it each time I re-draw the original graphics, and creating new instances each time doesn't seem a good practice. Quote Link to comment Share on other sites More sharing options...
lmfielding Posted August 16, 2019 Share Posted August 16, 2019 It is only a new graphics instance, how many are you planning on making? When they aren't being rendered any longer garbage collection (optimisation) is easy, even if you know nothing about it... a lot of it is automatic. Quote Link to comment Share on other sites More sharing options...
soylomass Posted August 16, 2019 Author Share Posted August 16, 2019 1 minute ago, lmfielding said: It is only a new graphics instance, how many are you planning on making? When they aren't being rendered any longer garbage collection (optimisation) is easy, even if you know nothing about it... a lot of it is automatic. It's a drawing app and the polygons have to be re-drawn each time a vertex is moved, it could happen once per frame (60 times per second) while a vertex is being moved. That's 60 graphics created in a second. They will be cleared by GC but it MAY create a spike in memory consumption that slows down the game for an instant. Haven't tried yet though. Quote Link to comment Share on other sites More sharing options...
lmfielding Posted August 16, 2019 Share Posted August 16, 2019 Should be fine, give it a try. If you need someone to test it then take my contact details, I could use a PIXI contact. soylomass 1 Quote Link to comment Share on other sites More sharing options...
lmfielding Posted August 16, 2019 Share Posted August 16, 2019 Your translation project looks incredibly cool too. I know a bit about i18n soylomass 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 16, 2019 Share Posted August 16, 2019 1 hour ago, soylomass said: Because I want to do it each time I re-draw the original graphics, and creating new instances each time doesn't seem a good practice. There's a way to hack vertices in 5.1.1 . Unfortunately, someone erased my playground that shows it (pixi-playground can be edited by anyone) You can hack inside "graphics.geometry.graphicsData" , change shape points and lineStyle/fillStyle. You have to call "graphics.gepmetry.invalidate()" afterwards. As for cloning - it doesn't copy geometry, it just links to the same. You can have several graphics with different transforms but geometry is the same. It was discussed here, but examples are wrong, someone overrode them by mistake: soylomass 1 Quote Link to comment Share on other sites More sharing options...
soylomass Posted August 16, 2019 Author Share Posted August 16, 2019 1 hour ago, ivan.popelyshev said: There's a way to hack vertices in 5.1.1 . Unfortunately, someone erased my playground that shows it (pixi-playground can be edited by anyone) You can hack inside "graphics.geometry.graphicsData" , change shape points and lineStyle/fillStyle. You have to call "graphics.gepmetry.invalidate()" afterwards. As for cloning - it doesn't copy geometry, it just links to the same. You can have several graphics with different transforms but geometry is the same. It was discussed here, but examples are wrong, someone overrode them by mistake: I just tried clone(). It looks like it takes the geometry by reference, so a change in the first graphic is reflected in the second, that's exactly what I needed! Thanks ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
soylomass Posted August 16, 2019 Author Share Posted August 16, 2019 2 hours ago, lmfielding said: Your translation project looks incredibly cool too. I know a bit about i18n Thanks! Actually it has been inactive for a while since I'm working on a lot of things at the same time, but I really like that project. About the project related to this post, it's a map editor for one of my games, I'll make it's source public once I finish some of its main features. Quote Link to comment Share on other sites More sharing options...
lmfielding Posted August 16, 2019 Share Posted August 16, 2019 I'm working on a map too, feel free to message me if you want any help. I'm a very good JS programmer but I hate canvas/visuals. 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.