How do I make my game remember the player's map positition?

Get help using Construct 2

Post » Thu Jan 15, 2015 10:23 pm

So, in my game I have a map screen, Mario Bros 3 style, where the player moves on a grid from level to level like so:

Image

The problem I'm having is that I don't know how to make the game remember what level the player is at once they enter it. If the player, say, goes to level 2 and completes it, the game puts them back on the level 1 square when they leave the level and go back to the map because that's the default position. How do I make it so that the game remembers the player's position on the map screen?
Last edited by CJacobsSA on Sun Jan 18, 2015 2:10 am, edited 2 times in total.
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Thu Jan 15, 2015 11:13 pm

Add a global variable called 'level' or something, whenever the user moves between levels update the value appropriately. Whenever the map is opened, move the player to the level stored in the 'level' variable.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Thu Jan 15, 2015 11:47 pm

I'm not entirely sure how to do that but I think I'm halfway there. In order for the game to know what level the player will be going to, I have a global variable called 'atLevel' which is set whenever the player box object overlaps one of the level "buttons" like so:

Image

How can I make it so that the game sets the player to the button that has the corresponding 'atLevel' value? Like if level 2's 'atLevel' value is 2, how would I set the player there coming out of a level? I don't have to do 'System > atLevel = 2 > Playerbox_Map > Set position to level2button' etc. for every level button do I? Is there a more condensed way to do it?
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Fri Jan 16, 2015 12:11 am

The method you described would work and yes there is a more condensed way. I would personally have all of the level buttons as one sprite, and create multiple instances of it. Then the sprite has an instance variable called 'level'. Give the sprite an animation with every level icon, but set the animation to not play. Make each frame of the animation correspond to the instance variable. Then you can loop through all instances of this sprite to see which one has the corresponding level. See attached capx.

LevelButtons.capx
You do not have the required permissions to view the files attached to this post.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Fri Jan 16, 2015 3:18 am

Ah, thank you, this works nicely. I appreciate the help. :)
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Sat Jan 17, 2015 2:11 am

snipped, I figure it warrants its own thread so I made one for it
B
18
S
9
Posts: 103
Reputation: 1,817


Return to How do I....?

Who is online

Users browsing this forum: koops and 11 guests