import/export of an displayObject to/from a data table

Can anyone share the import/export  of an object to/from a data table (Including physical bodies and joints).?

I don’t know if I completely understand what you mean, but I don’t think that’s possible out of the box. It should be fairly simple for you to create a function that does that in your specific project.

I began to make the function not specific to my project, but universal. It should support all the properties of all display objects. It is not so easy. But why, if someone already has it?

Creating a universal solution to that IS difficult and a looooot of work. Most likely more work than anyone would be willing to undertake. In fact, there are plenty of information that simply isn’t accessible, like physics body and joint related information, etc.

But, in your own projects, you know specifically what information your objects hold that is of interest to you. You know exactly what information is passed to every object when it is created and so you know what you need to recreate them.

For the simplest information like height, width, x, y, rotation, etc. you can just copy them from the display object, but other than that, I’d simply add any relevant information at the moment you create said object or when you give them a physics body or add joints.

For instance, you could create a simple module that contains functions for creating any display object that YOU might need.

local new = {} function new.rect( ... ) local t = { ... } local object if type( t[1] ) == "number" then -- if it's a number, then the first argument isn't a group object = display.newRect( unpack( t ) ) else object = display.newRect( t[1], t[2], t[3], t[4], t[5] ) end object.type = "rect" -- object.fill -\> perhaps you need to duplicate the object's fill, so store it as well -- object.anotherVariable -\> store any and all important information to the variable return object end return new

Now, you could extend that module by creating a function “newJoint”, “copy”, etc. Again, you know exactly what information you pass along to the object when you create it, so you can just add a few lines of code to your module that will store these for you for if and when you need to copy a display object.

The simple fact is that there are an infinite ways of creating and combining display objects; for adding joints, physics bodies, fills, and such to them. Creating a single universal method for handling all of that would be expensive, time consuming and probably not that useful to most developers (and probably not even possible in a way that suits everyone), but the alternative, i.e. creating an approach that suits your needs specifically, is fast and easy.