soylomass

Copy Graphics content into another Graphics

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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: 

 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

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

  • Recently Browsing   0 members

    No registered users viewing this page.