Keeping an objects postion when switching layouts

0 favourites
  • 9 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • 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!

  • Global variables are the first thing that comes to mind, and should do the trick nicely.

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


  • 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.

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • I get it better now. Thanks!

  • 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.

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