How do I save animations between layouts?

  • The project I'm currently working on requires a sprite to change into different animations over time, but whenever I switch to a different layout and back to the layout the sprite is on, it goes back to the default animation. Is there a way to save whatever the current animation is between layouts? Also is there a way to save this even after closing the program?

  • You can save your current Animation into Local Storage.

    Then you can load it back when starting the game.

  • You could make a str variable called "CurrentAnim".

    On Layout End > Set "CurrentAnim" to "PlayerSprite.AnimationName"

    (this stores the name of the current animation as a str variable when you leave a layout)

    On Layout Start > PlayerSprite Set Animation > CurrentAnim

    (this will take your str variable, and set your player's sprite to the previously stored animation)

    Hope that helps.

  • You could make a str variable called "CurrentAnim".

    On Layout End > Set "CurrentAnim" to "PlayerSprite.AnimationName"

    (this stores the name of the current animation as a str variable when you leave a layout)

    On Layout Start > PlayerSprite Set Animation > CurrentAnim

    (this will take your str variable, and set your player's sprite to the previously stored animation)

    Hope that helps.

    Does the str variable have to be constant or no? Also should I just set the Initial Value to 0, or just not add anything there?

  • You can save your current Animation into Local Storage.

    Then you can load it back when starting the game.

    Can you elaborate on this? Like what would the process for this be?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can do similar like this:

  • You can do similar like this:

    So I tried something based of of this, but nothing I try seem to work. Every time I switch between layouts and back to the one the sprite is on, I'm getting same result as before. Here's the current code so far:

    Global String: cur_anim =

    System > On start of Layout > LocalStorage > Check Item "cur_anim" exists

    Local Storage > On Item "cur_anim" exists > Get Item "cur_anim"

    Local Storage > On Item "cur_anim" missing > Sprite > Stop animation

    Local Storage > On Item "cur_anim" get > Sprite > Set animation to LocalStorage.Item Value (play from beginning)

    Sprite > is "NewAnimation" playing > set item "cur_anim" to Sprite.AnimationName

    Is there anything I' doing wrong here?

  • My "cur_anim" is a key of Local Value not Global variable so please check on your side again.

  • what if you use the persist behavior?

    Make a separate instance variable and every time you change the frame, also set the instance variable to that frame number.

    On start of layout set frame to that instance variable

    I think the persist behavior should retain the instance variable

    but maybe I don't understand the business case fully...

  • My "cur_anim" is a key of Local Value not Global variable so please check on your side again.

    I'm sorry, I've been trying to figure this out but I'm a bit lost here. How do I make "cur_anim" into a local value? I can't seem to find it anywhere.

  • I'm sorry, I've been trying to figure this out but I'm a bit lost here. How do I make "cur_anim" into a local value? I can't seem to find it anywhere.

    When you save to Local Storage, you can set that key name to call it back when load the game.

  • > I'm sorry, I've been trying to figure this out but I'm a bit lost here. How do I make "cur_anim" into a local value? I can't seem to find it anywhere.

    When you save to Local Storage, you can set that key name to call it back when load the game.

    So is it as simple as Local Storage > Key = "cur_anim"? Or am I missing the point here?

  • You could watch this video where I use the local storage plugin to store a variable for the best score, and then load the best score when the game starts again.

    You can use it to store cur_anim.

    youtu.be/6Lyj2oQexGU

    good luck

    cheers

  • My apologies, I didn't have notifications turned on for this thread.

    While the other solutions may work, this is probably the simplest way to do it IMO. Works in my game currently.

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