How do I control character placement on layout change?

0 favourites
  • 7 posts
From the Asset Store
2d mushroom sprite 2d game mushroom character enmy sprite game art
  • I am working on a side-scrolling game and have been stuck on controlling where my character appears when I have sprite change layouts. Ideally I am going to use the borders as well as "doors" or exits on the layout and so the player will have multiple locations they can appear depending on which exit they came from.

    I've been trying the method of using using a sprite box as the trigger to load the appropriate layout. On layout load I am using "set PLAYER to POSITION X and Y". I also tied "set PLAYER to POSITION of object" and placed an object where I want the player to spawn.

    Any ideas on how to set where the player loads on layout change?

  • Hey chromaticcodex,

    One possible approach:

    1. For the exit objects, add a private text variable named "exitName".

    2. For each exit object, set "exitName" to a unique name. ... (e.g. "snakeTunnel", "lavaTunnel", "spikeTunnel", "comfyPillowTunnel")

    3. Do this for each layout, making sure the doors that are supposed to be linked between layouts have matching names.

    4. Now, create a global variable named "gLastExitUsed". ... (globals are unchanged between layouts)

    5. When the player leaves through an exit object, get the text in the exit's "exitName" and store it in the "gLastExitUsed" global.

    6. Jump to the new layout.

    7. On start of layout, pick the exit object with the "exitName" that matches the "gLastExitUsed" global. Place the player at that door, as if they just entered through it.

  • ...I'm not sure where you're having problems? It really sounds like you've got it under control.

    That said, if you *were* having problems, fisholith has gone into serious detail for you.

  • fisholith- thanks! I haven't quite figured it out yet, but using what you wrote has gotten me closer, I just don't think I am using the global variables correctly yet. You're awesome though!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Take a look at this fellow, see what you think.

  • Unnatural20 - Your fellow there has really helped. For the first time I was able to set where exactly the player loaded on a layout change. The capx is a great starting point. Making it work all on one event sheet is the only adjustment I will need to make, but I think that should be relatively easy but again this is a huge step forward. From the looks of it all I need to spend some time learning more abut expressions. Thanks, both of you!

  • yeah the method you mentioned was limited, so I added using a dictionary and pasting an "exit group" in each new event sheet.

    This took me a week to figure out, but here you go.

    How to use dictionay vid:

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