Remember player position when changing layout

Get help using Construct 2

Post » Fri Jan 17, 2014 10:31 pm

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?neutrinox2014-01-17 22:32:05
B
9
S
1
Posts: 97
Reputation: 715

Post » Sat Jan 18, 2014 1:35 am

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.

ArcadEd2014-01-18 01:36:37
B
101
S
32
G
11
Posts: 1,546
Reputation: 21,727

Post » Sat Jan 18, 2014 1:42 am

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).
B
98
S
35
G
20
Posts: 438
Reputation: 17,875

Post » Sat Jan 18, 2014 7:46 am

I would do as ArcadeEd suggested, just pass the info through a global variable and recall it.
Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061

Post » Sat Jan 18, 2014 1:28 pm

Persist behavior should be enough... but the porblem its all the other element like enemies... bullets ect...
B
23
S
6
G
3
Posts: 316
Reputation: 3,461


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests