Use webstorage to load a "scene"

Get help using Construct 2

Post » Wed Jan 30, 2013 4:25 pm

I am building a game where you build a scene (puzzle game) using system created objects. I am aware that WebStorage does NOT store objects but rather stores values and keys. If I have 50 different sprites on one layer how can I most effectively save and load a saved project.
If I can't use webstorage please send me in the right direction.

Thanks!
B
6
S
1
Posts: 25
Reputation: 675

Post » Wed Jan 30, 2013 7:03 pm

I also have a layout with sprites, that the user should be able to save.. don't know how.
sry for bumping
B
5
Posts: 55
Reputation: 585

Post » Wed Jan 30, 2013 8:19 pm

Appreciate the bumbp actually! Not getting too many bites on this one.

I am wondering if we can store an array of object names and their X,Y so they can "load in" perhaps using system create object on load. Even if the load is actually re-creating the scene it would work well.

Object1 X=123 Y=123
Object2 X=321 Y=321

Allowing a user to "load" using those objects and have them placed in the scene is a crucial part of my design.
boggler2013-01-30 20:22:50
B
6
S
1
Posts: 25
Reputation: 675

Post » Wed Jan 30, 2013 9:07 pm

@boggler - sounds like a cool project, dude.

I haven't done anything quite like that, but I can think of a few suggestions that might help give you some ideas.

I'm not too familiar with arrays, so I got nothing on that--sorry, man. Arrays, AFAIK, don't translate well into WebStorage. Using an array might be the easiest as far as functionality goes, though. Loading/retrieving Arrays is still a bit mystifying to me. :)

- If there are fixed positions on the "board", each of those positions could relate to a WebStorage key. By using a System Loop, you can have the game go through each key and load the object that should belong in that spot. If spot1 corresponds to 32x,64y, the WebStorage key could be "spot" & loopindex. The value could be something you assign to an instance; maybe value = "block". A separate function could call if value = "block", create object block at 32x, 64y (the spot coordinates).


- If everything is fluid positioning, use the same system loop to search by the object type. Maybe loop through webstorage keys like "block" & loopindex; if the loop returns a 0, tell it to stop as no more blocks were found on the screen. Each key found of an object type may have a value of it's X/Y positioning. If a key/value is found, the game creates the object at the saved coordinates.

I stink at explaining these types of things, but maybe the basics of the idea might help.

Take care
B
16
S
6
G
2
Posts: 152
Reputation: 3,764

Post » Wed Jan 30, 2013 9:30 pm

@ape
hmm time to fool around with that first concept you have.
I think that might work. Will post my findings in a few.
B
6
S
1
Posts: 25
Reputation: 675

Post » Wed Jan 30, 2013 11:06 pm



In the attached CAPX I have an object that is moved around using Drag / Drop. Its location can be saved using "Save". This saves to Local Webstorage using Sprite.X. The local file is saved as "XLoc".

I created a "Load" button and am able to load in the JSON data to make sure it is loading properly - and it is.

My next step - Which is not working is that I want to SET LOCATION of Sprite to XLoc Sprite.X (the X coord in the in XLoc within Webstorage) I can't seem to figure the code out for this.

Can someone who is good with code take a look at it, it is a very small CAPX.
Thanks.

Don't have reputation so you will have to copy and paste.
https://www.dropbox.com/s/m7mjt8nib468nl8/LoadSpriteLocationFromWebStorage.capxboggler2013-01-30 23:07:40
B
6
S
1
Posts: 25
Reputation: 675

Post » Thu Jan 31, 2013 12:02 am

Sprite: Set X to float(WebStorage.LocalValue("XLoc"))
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Thu Jan 31, 2013 12:45 am

@ramones

Fantastic - thank you.

Long way to go still but something basic learned today!
B
6
S
1
Posts: 25
Reputation: 675

Post » Thu Jan 31, 2013 6:03 pm

Here's an example of saving object positions. You need a separate create object event for each different sprite you have so if you have 50 different sprites you'll need 50 different events.

You might be able to use the nickname plugin for spawning objects by name if you don't mind using third party plugins (haven't tried it myself).

saveAndLoadPositions.capx
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Thu Jan 31, 2013 6:58 pm

thanks again ramones.
One off the topic question can you turn a IMG from URL into a sprite or pin that image to a system created sprite? Thats my last hurdle.
My fantasy is to have a XML file with all the sprite values / variables and the img URL and then something like this would run:
System > Every Tick
System > For Each IMG from URL create object IMGSprite
On Click > IMG from URL Pin to IMGSprite.ImagePoint(0)

That way every image I load into my game can become a sprite.
If I can't do this with C2 I am sure it can be done using Javascript.
Sounds like an addon IMO.

I can't thank you all enough for your help, its a lot of fun to get intelligent feedback.
B
6
S
1
Posts: 25
Reputation: 675

Next

Return to How do I....?

Who is online

Users browsing this forum: makkancs and 24 guests