Keeping an objects postion when switching layouts

Get help using Construct 2

Post » Wed Mar 06, 2013 7:38 am

Hi

I'm curious to know how to keep an objects position after I trigger an event that switches to another layout. e.g A player object walks to the shop door which lead's to a layout which is the inside the shop. When the player exits the shop I would like the player's to be standing near the door.

I was thinking along the lines of using global variables to set the players position. And saving them once he entered the shop, then reloading them once he exits it.

Sorry if this isn't so clear.

Thanks in advance!
B
5
Posts: 13
Reputation: 676

Post » Wed Mar 06, 2013 8:51 am

Global variables are the first thing that comes to mind, and should do the trick nicely.
Mistakes were made.
B
37
S
17
G
67
Posts: 1,041
Reputation: 38,211

Post » Wed Mar 06, 2013 9:34 am

Thanks for the reply. I've got it working now

:)
B
5
Posts: 13
Reputation: 676

Post » Wed Mar 06, 2013 4:27 pm

instance variables will work too, if you decide you want to track more than just the player's position. I hate the idea of using globals for anything that I don't have to. Anytime I clutter up the global namesapace, I run into trouble down the road.
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Wed Mar 06, 2013 7:28 pm

I am keeping everything dynamic in a Dictionary object... which is a global object... is that bad? What kind of "trouble" did you run into?
B
6
S
3
G
1
Posts: 102
Reputation: 1,379

Post » Wed Mar 06, 2013 7:53 pm

I just find that using global variables for things that aren't truly global in scope, leads me astray.

I'm not really talking Construct 2 here, more Javascript and programming in general. I'm a total C2 noob, so I can't say one way or the other about your solution. What do you mean "everything dynamic"?

I personally try to keep everything relating to an object within that object as much as I can.

So for example I like to put position and rotation stuff in the object that handles collision, and animation logic and the like into the object that handles sprite changes. Even though I might otherwise be tempted to handle things like "is the player shooting" or "where is the player" globally since there is only one player.

http://oreilly.com/javascript/excerpts/javascript-good-parts/awful-parts.html
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Wed Mar 06, 2013 8:02 pm

He's keeping information between layouts, so I believe he needs to use a global variable or store the information in an array or dictionary. Otherwise the data will be lost when he changes layouts (new instance of player object).

Could be wrong though, I'm pretty new to Construct too.
Mistakes were made.
B
37
S
17
G
67
Posts: 1,041
Reputation: 38,211

Post » Wed Mar 06, 2013 8:31 pm

I get it better now. Thanks!
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Wed Mar 06, 2013 8:57 pm

I am fairly new to construct as well. Yes I wanted to use a global since I was assumed that the scope of an instance variable was only within the layout it was created in.

B
5
Posts: 13
Reputation: 676


Return to How do I....?

Who is online

Users browsing this forum: michaelverdi and 29 guests