How to prevent the parallax of all layers being restored from a JSON savegame?

0 favourites
  • 11 posts
From the Asset Store
Set of 10 Parallax Background to make pixel art game.
  • How can we prevent the parallax of all layers being restored from the JSON? It would be so nice to have the possibility to enable/disable more options for this feature, like for saving the parallax of each individual layer.

    My planned workaround is to save the actual parallax values for each layer in variables (just before loading the JSON), parse the JSON string (that I am storing via AJAX on my MySQL database) and replace the parallax values of each layer in the JSON string by the ones stored in variables. But it's not elegant, it's more work, and it's also maybe a bit too glitchy since the parallax values can have changed during the time the JSON is being processed, returned and applied. Any idea?

  • I don't understand what JSON has to do with parallax setting, but you can save parallax values in Local Storage before loading the game, and then read them from Local Storage after the game was loaded.

    Another option is to create a dummy object (an empty sprite for example) with No Save behavior. You can add a bunch of instance variables to it and use them to keep parallax values.

  • I don't understand what JSON has to do with parallax setting, but you can save parallax values in Local Storage before loading the game, and then read them from Local Storage after the game was loaded.

    I am saving the SaveStateJSON, then loading game from JSON string AJAX.LastData. Of course I can exclude things I want to save by applying them the NoSave behavior. What I wanted to do is the equivalent of adding a NoSave behavior on the layers parallax, but it seems impossible to do just as simply as adding a behavior. Your idea of the dummy object is indeed better than mine using variables because those would continue to be updated even during the processing of the JSON, so thanks Dop2000 :) It will prevent the need for parsing the JSON, since I will apply the JSON (load game) normally, except right after I will follow up with updating the layers parallax values with the ones stored in the dummy. I just hope nothing will flicker, but for sure I go try it.

    Now any idea also why anything using "Load image by url" won't be restored after restoring a savegame...?

  • If there is flickering, you can hide/mask it with a short fade-in effect.

    I don't know why images loaded from URL are not saved. You can save/restore them separately using these addons:

    construct.net/en/forum/extending-construct-2/addons-29/behavior-extract-sprite-to-bas-46034

    construct.net/en/forum/extending-construct-2/addons-29/behavior-inject-base64-string-46061

  • You can add a bunch of instance variables to it and use them to keep parallax values.

    How can I actually set an instance variable's value to be the parallax value of a layer?

    As explained there scirra.com/manual/28/layer, something like: layer.parallaxX > It tells me that layer is not an Object.

    About why images loaded from URL are not saved, thanks.

  • LayerParallaxX(n) where n is the layer number or name.

  • Thank you so much! I found that nowhere in the manual and nowhere on Google..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Last thing, now that I can GET the values of a parallax, how I can SET a parallax by injecting values?

  • Nevermind my question, consider this solved.

    I think I will have to take a different approach for my camera. Right now I am only using a button to pan the scroll area:

    On Middle button Clicked | System Set dragging to 1, System Set sMX to Mouse.AbsoluteX, System Set sMY to Mouse.AbsoluteY

    System dragging = 1 | System Scroll to (sSX+sMX-Mouse.AbsoluteX, sSY+sMY-Mouse.AbsoluteY)

    I will change that for when dragging, move a target sprite which has the ScrollTo behavior enabled. This way I will be able to restore the camera position easily without the need to get and set the parallax values manually.

    It's very basic stuff but apart from restoring the layers parallax values after a game load I had no use for such a camera system so I not thought of that approach like I would usually in other game projects. However I am sure I will find other uses soon :)

    Thanks again!!

  • I don't understand what JSON has to do with parallax setting, but you can save parallax values in Local Storage before loading the game, and then read them from Local Storage after the game was loaded.

    Another option is to create a dummy object (an empty sprite for example) with No Save behavior. You can add a bunch of instance variables to it and use them to keep parallax values.

    JSON is the format in which the content of the SaveStateJSON variable holds the state of all project assets that DON'T have the NoSave behavior applied, like layer parallax, since the state of more general settings is also applied, like layer settings.

    The solution was very easy in fact and is your second suggestion, the dummy object with NoSave behavior. I didn't even had to use a bunch of instance variables however, I simply added the ScrollTo behavior and it worked like a charm without NO flickering ever, even without the use of any lerp.

  • > I don't understand what JSON has to do with parallax setting, but you can save parallax values in Local Storage before loading the game, and then read them from Local Storage after the game was loaded.

    > Another option is to create a dummy object (an empty sprite for example) with No Save behavior. You can add a bunch of instance variables to it and use them to keep parallax values.

    JSON is the format in which the content of the SaveStateJSON variable holds the state of all project assets that DON'T have the NoSave behavior applied, like layer parallax, since the state of more general settings is also applied, like layer settings.

    The solution was very easy in fact and is your second suggestion, the dummy object with NoSave behavior. I didn't even had to use a bunch of instance variables however, I simply added the ScrollTo behavior and it worked like a charm without NO flickering ever, even without the use of any lerp.

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