Giedrius Posted March 2, 2018 Share Posted March 2, 2018 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: Quote Link to comment Share on other sites More sharing options...
Giedrius Posted March 2, 2018 Author Share Posted March 2, 2018 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: Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 2, 2018 Share Posted March 2, 2018 Why do you need to clone the container in first place? Quote Link to comment Share on other sites More sharing options...
Giedrius Posted March 2, 2018 Author Share Posted March 2, 2018 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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 2, 2018 Share Posted March 2, 2018 Pixi doesnt have features for persistance, you are on your own there. Try look at https://github.com/GreyRook/POM Quote Link to comment Share on other sites More sharing options...
botmaster Posted March 5, 2018 Share Posted March 5, 2018 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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 6, 2018 Share Posted March 6, 2018 Well, its easier than in flash anyway. Whats the problem? 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.