Door to travel between layouts

Get help using Construct 2

Post » Sat Nov 02, 2013 1:34 pm

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
B
5
Posts: 19
Reputation: 265

Post » Sat Nov 02, 2013 2:10 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Nov 02, 2013 2:54 pm

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.
B
5
Posts: 19
Reputation: 265

Post » Sat Nov 02, 2013 4:22 pm

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.PixelHero2013-11-02 17:19:42
B
15
S
5
G
2
Posts: 24
Reputation: 2,054

Post » Sat Nov 02, 2013 7:40 pm

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.

Twyzer2013-11-02 20:29:52
B
5
Posts: 19
Reputation: 265

Post » Thu Dec 05, 2013 7:03 pm

here is an example with plataform template door.capx
Carlo Andrei Mercado

Animator, illustrator, concept artist, special effects for games.

[email protected]

http://f-fman.wix.com/portfolio-ffman22

http://ffman22.deviantart.com/



tutorials:



https://www.scirra.com/tutorials/950/dynamic-mini-map dynamic-mini-map tutorial



https://www.scirra.com/tutorials/9479/p ... ing-damage falling damage platform tutorial



originally published by ffman22
B
62
S
19
G
4
Posts: 340
Reputation: 6,606


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, kellehk, Yahoo [Bot] and 29 guests