Jump to content

Copy Graphics content into another Graphics


soylomass
 Share

Recommended Posts

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.

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

Link to comment
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: 

 

Link to comment
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

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

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