How do I Switch Between Layouts Properly

Just started using Construct 2? Post your questions here

Post » Thu Apr 02, 2015 5:15 pm

Hi, I've just created a title screen layout, and I also have a layout for Room1. I've got it to go to Room1 and start the game when I click on the "Start" button from the Title Screen layout. Now, when the game switches to a new layout, shouldn't everything disappear from the previous layout? I'm still seeing the title screen objects when I'm running the Room1 layout (and vice versa). I've got it set up so that if I hit the 'Esc' button while in Room1, it saves the game, then, on save, it goes to the title screen layout where the options are, and then I can return to the game. Is there some steps missing?

As a separate question, I've also made all the objects in the game global. Is there a reason to have non-global objects?

Thanks
B
4
Posts: 29
Reputation: 264

Post » Thu Apr 02, 2015 6:21 pm

Well, on experimenting, I switched the menu objects in the title screen layout to non-global and that seems to have fixed the problem. I'm still curious about what will happen when I make future "Rooms". Do I need to make the objects in the main game, like the characters and smashable tables, non-global as well? I want to be able to return to a room and see the dead bodies and broken objects still lying around, but I don't want to see objects from multiple layouts at the same time. I'll try the persist behavior for those things.

Maybe the global objects should just be limited to the HUD/GUI objects?
B
4
Posts: 29
Reputation: 264

Post » Fri Apr 03, 2015 11:25 am

By default most visual objects in layouts are non-global.
As such, when you move from a layout to another, all the non-global instances are destroyed. Global object just means that moving from a layout to another, the instance is not destroyed and stays on screen (which is not what you are trying to achieve).

If you are looking to have access to your menu even when ingame, you can look into making it a global layer.

To have "persistent" rooms, you have several ways to do so.
a/ Each room layout is a different layout in your game. As such, use the persist behavior for your objects.
b/ Each room is drawn on the same layout, you dynamically load/save/keep the current states of the room in some data structure (array likely).
A bit more difficult, needs a lot of organisation, you need, when leaving a room to keep somehow in memory the position/state/all useful infos in relation to the objects on screen. And you need when entering the room (likely the condition "On start of layout" or a function of your choice) to first destroy everything, and then place the correct instances in the correct positions/states you saved them in.

It's doable, it just require more events work on your side and a careful organisation/data structure/planning of what and how to keep it in memory.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
295
S
118
G
96
Posts: 7,328
Reputation: 71,248


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest