How do I save/load all properties of all sprite using a file

Get help using Construct 2

Post » Wed Aug 24, 2016 2:15 pm

I'm doing a 2d tool program based on sprites.

I'm looking how to save all the sprites properties like: Name, X/y position, instance values, opacity,effect parameters,etc... in a file and after in a new runing load that file that create all the sprites with their properties to regenerate the same composition.

I saw the sprites have a AsJSON and "set from JSON" but, how i tell the code how to create the sprites and how many sprites and in which one add what properties ¿?

I search in the forum and i saw this one:
r196-setting-sprite-from-json-ignores-sprite-blend-mode_t124121

Changing the SaveState to text instead a global number save/loads the properties of the object, but i have no idea that how do the rest.

I guess, at least for save, create a family called "sprites" and using an Array plugin and then: For each sprite save their JSON state in a X. so i will have stored in each X(x1,x2,x3) the properties of each sprite. But how i save all that in a .txt o .JSON file and how load all that after to recreate the same composition? :S

I tried another way using the System:save but each file gets near 80mb and saving is a bit slow, works but is not an option :( .

So, how i do the .json thing?
B
27
S
10
G
3
Posts: 598
Reputation: 4,648

Post » Wed Aug 24, 2016 5:56 pm

Well, at least now i can save and load the family sprite states using json and arrays in the runtime.
https://dl.dropboxusercontent.com/u/659 ... tate2.capx

Now i guess is export the Array.JSON state. SO in a new running i will load the arrays and a for each to any sprite.

But if i create more sprites, and if i run the app without any sprite, how i tell the program he have to create a sprite of X type and set their properties?
B
27
S
10
G
3
Posts: 598
Reputation: 4,648

Post » Wed Aug 24, 2016 6:44 pm

Well, you can save & load the sprite states on runtime.
https://dl.dropboxusercontent.com/u/659 ... tate4.capx

You can Press Circle or Square to create them and drag anywhere and works in the same app.

Works the export button of Array.AsJSON

So the unique problem still is create the objects and add their properties of the Array.asJSON. And well discover how open a file and get the text instead of put the direcction by default on import.

Still nothing how to solve that?
B
27
S
10
G
3
Posts: 598
Reputation: 4,648

Post » Wed Sep 21, 2016 7:52 pm

@matriax
So you want to create objects using properties saved in .json file, right?
Seems as we do running into similar issue in our projects. You've made a bigger progress tho. Well done!
I'll take my time to inspect your work.
I'm a Magician, not a Developer.
B
23
S
8
G
25
Posts: 106
Reputation: 14,344

Post » Wed Sep 21, 2016 9:26 pm

When you load just re-create the objects from the array. The only problem is while saving can be done with a family, you need to create the individual sprites instead of creating the family.

You can look here for something similar:
viewtopic.php?f=147&t=167097&p=1007621&hilit=save+load#p1007621
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests