How do I set position after switching layout?

  • Hi all. As the title said it, I'm trying to make my character to be on the last position of it was after switching back and forth of the layout.

    For example, I talked, one of the NPC, then it will bring me to the "Teaching" layout. Then after I'm done with the layout, it will be on the last position but that did not happen. I did tried to make it once, but it brings me to the initial character position on start of the "School" layout. I'm still new on this position thing.

    Here is my .capx:

    goo.gl/3SGRUZ

  • Can't view your capx as I'm on mobile - but I would add two global variables to store your position. Call them something like 'ReturnToX' and 'ReturnToY'. Before switching layouts, set the global variables to the player's X and Y. After switching back, set the player's X and Y to the contents of the variables. This will allow you to always recall the player to their position before the last transition *only*.

    To recall more than one transition, you might want to add a Dictionary object. When the player leaves a layout, add a key to the dictionary named Player.LayerName, with the value Player.X&","&Player.Y. When the player enters a layout, set their X to int( tokenat( Dictionary.Get( Player.LayerName ), 0, "," ) ) and their Y to int( tokenat( Dictionary.Get( Player.LayerName ), 1, "," ) ) . This will continually track the player's last location in as many layouts as you have, so long as all layouts have the necessary events. The Dictionary is a global object, so its contents are always available to all event sheets.

  • Thank you for your response. According to your suggestion, should I make my player sprite's name to be the same as my "Town" layout? Because each player character on each layout have different sprite name.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would definitely try and make it so that the player was represented by the same sprite object everywhere they're present. You're lining yourself up for a headache.

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