Use webstorage to load a "scene"

0 favourites
  • 10 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • 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!

  • I also have a layout with sprites, that the user should be able to save.. don't know how.

    sry for bumping

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

  • APE

    hmm time to fool around with that first concept you have.

    I think that might work. Will post my findings in a few.

  • 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.

    dropbox.com/s/m7mjt8nib468nl8/LoadSpriteLocationFromWebStorage.capx

  • Sprite: Set X to float(WebStorage.LocalValue("XLoc"))

  • ramones

    Fantastic - thank you.

    Long way to go still but something basic learned today!

  • 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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)