Giedrius

Clone the PIXI Container

Recommended Posts

Hi all,

I am trying to clone an PIXI Container so that it will have no relationship with the original one, except that they both should share the same prototypes - DisplayObject, EventEmitter, Object. But somehow I loose the original Container, see demo: 

 

 

 

Share this post


Link to post
Share on other sites

Oh, I see, the assignment operator doesn't create a copy of an object, it only assigns a reference to it. So I need to make a deep copy with Object.create, but it still removes the original container: 

 

Share this post


Link to post
Share on other sites

I am creating a venue designer where user can create sectors of seats, customize them and duplicate to place on the other side of the venue. It would be convenient and time saving feature. So the sector is a container which holds row containers with seat objects inside.

As I understand, one way would be to make a manual copy, creating an new Container and assigning properties of the original Container.

Share this post


Link to post
Share on other sites

That's where OOP help (I work with typescript but same can be done in javascript), just make your seat objects extends whatever they are (Sprite?, Container?) and add a clone method in there, in that clone method make it duplicate relevant properties and assets and return the result in a new object and you are done. Cloning is the simplest thing in any technology, binary cloning is harder but I don't think it's an option in javascript.

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.