Door to travel between layouts

  • Hello fellow devs,

    I am developing a side-scrolling platformer game with different zones, for example cave, mine, etc. What I would like to do is to travel between these layouts by pressing a button while standing on a door sprite.

    An example: On the 'level1' layout, there is a secret room, accessible through a hidden door. I get to the door, press a button while standing on its sprite. Now I'd like the game to put my player onto the 'level1_secret' layout to a specific position (to the other side of the door, which uses the same sprite) with all my stats saved. If I want, I can use this door again to get back to the 'level1' layout (in the specific position as well).

    It would be easier if I could set a value to a door, so I can create events to a specific one and not for the object itself. Probably I'm missing something, but I can't really find a way to solve this issue.

    Thanks in advance,

    Peter

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • using instance variables you can set a numeric or text-value to any object on your layout. I guess that's what you are looking for. I can't imagine they aren't used in the basic tutorials, so I assume you haven't followed those. I recommend you do, because they tell a lot about the basic things you should know to create games with construct.

  • In my understanding, you can set the value of instance variables, but what I want is ordering exactly one number to the door sprites. So there is e.g. one 'door' sprite with a 'number' value of 6. Whenever I set an instance variable of a single door, it applies to the others as well.

  • That probably is happening because your event sheet isn't picking a door instance. If you don't have a specific instance picked by an event, then the action happens to ALL instances.

    So for instance, something like:

    * System | On start of layout

       local variable newDoorID = 0

       * System | For Each [] Door

            Door[] | Set doorID to newDoorID

            System | Add 1 to newDoorID

    This will cause each door to get a unique ID at the start of the layout. If you want globally unique door IDs, then just make newDoorID a global, rather than an instance of the on start layout. You can also do a for-each ordered if there is another criteria that you want to use to determine the IDs (such as position along the x axis, or something)

    If you want, you can also save the level to load in a text instance variable on the door, and then use common code like the following (you'll have to add in the stat saving and all, sorry)

    * Keyboard | On [use your key here] key pressed

       * Player | is overlapping [] Door

       * Door | X Is Locked                           //Just an example

          * System | Go to layout Door.levelToLoad

    For an example. Of course you can spruce it up, but at least then you don't have to do any custom mapping of doors to levels.

  • I've managed to solve it. I had to make a modification so when I get back to the main chunk of the level, 2 is substracted from the door IDs to grant the ability to re-enter the sublevel rooms (this way the room instance variable to the secret room stays the same when on the main stage). Also, since my camera is basically at the start of the main level, my larp function caused it to fly to the player over almost 2 seconds when got back from the secret room. To solve this I moved it over the player on start of layout.

    <img src="https://lh3.googleusercontent.com/-_sJc_rgQVqw/UnVfNaiZbKI/AAAAAAAANdI/cwpbXdOMv4E/w823-h607-no/construct_doors_events.png" border="0" />

  • here is an example with plataform template door.capx

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