0 Favourites

Remember player position when changing layout

  • Hi!

    I have two layouts, main and shop.

    When player enters the shop from the main layout, and then again exits the shop, the position of the player resets to the beginning of the main layout.

    I tried to set the position in the event sheet of the shop like this:

    button-->on clicked-->player sprite-->set position to (4000,1000);

    system-->go to main layout;

    That didn't work; the location of the player still resets to the beginning of the level.

    How could I make the player appear outside the shop door when he exists?

  • I show this in my platform tutorial (going in a tunnel and coming out) but basically like this.

    Variables:

    isShop = 0

    playerX =0

    playerY = 0

    Just before the event to change to the shop layout set:

    isShop = 1

    playerX = Player.X

    playerY = Player.Y (Player is whatever the name of your player object is).

    Then on start of layout for the main layout create a sub event:

    If isShop = 1

         Set Player Position = playerX and playerY

         Set isShop = 0

    Something like that :). Then you a have that sub event for other changes that take effect after leaving the shop.

  • You can add the Persist Behavior to objects to have then remember where they were (they don't get destroyed when the layout ends and then recreated when you go back to the layout).

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I would do as ArcadeEd suggested, just pass the info through a global variable and recall it.

  • Persist behavior should be enough... but the porblem its all the other element like enemies... bullets ect...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
195 16,197
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
0 Favourites
[plugin] Youtube player
175 20,538
rexrainbow's avatar
rexrainbow
Unread hot topic
132 29,587
chadorireborn's avatar
chadorireborn