How do I control layers?

Just started using Construct 2? Post your questions here

Post » Sat Sep 17, 2016 1:05 am

Hi, I'm having a problem where I have most of my main objects on layer 0, and I'd like to add a layer below that layer. This makes the new layer 0 and the old layer 1. Is there a way to have all of the events in my event sheet refer to the objects in their correct, new layer 1 instead of layer 0 in a way where I don't have to change each event by hand?

Thanks!
B
22
S
8
Posts: 9
Reputation: 1,470

Post » Sat Sep 17, 2016 3:53 am

sanderstyler wrote:Hi, I'm having a problem where I have most of my main objects on layer 0, and I'd like to add a layer below that layer. This makes the new layer 0 and the old layer 1. Is there a way to have all of the events in my event sheet refer to the objects in their correct, new layer 1 instead of layer 0 in a way where I don't have to change each event by hand?

Thanks!


Just curious, sanderstyler. How are you currently referring the objects in layer 0? I'm curious, because I haven't had any issues with objects residing in old layers after adding new layers nor after changing layer orders..
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Sat Sep 17, 2016 8:06 pm

Hi, thanks for your reply.

An example could be:

On condition -> Create object on layer 0

Whenever I add a layer below layer 0, the new layer becomes 0 and the old layer becomes 1. However, in the event sheet, the event still says

On condition -> Create object on layer 0

I'd like know if there's a way to make all of the events that refer to 0 start referring to 1 after I add the new layer
B
22
S
8
Posts: 9
Reputation: 1,470

Post » Sat Sep 17, 2016 9:44 pm

sanderstyler wrote:Hi, thanks for your reply.

An example could be:

On condition -> Create object on layer 0

Whenever I add a layer below layer 0, the new layer becomes 0 and the old layer becomes 1. However, in the event sheet, the event still says

On condition -> Create object on layer 0

I'd like know if there's a way to make all of the events that refer to 0 start referring to 1 after I add the new layer


Thank you for the update, sanderstyler.

The layer name should stay the same. I have just tested and confirmed.

Case study

1. Create a new sprite object named 'Player'.
2. Create a new layer named 'Layer 1'.
3. Go to Event Sheet and create a new event [System] -> [On Start of Layout].
4. Under [On Start of Layout], create [System] -> [Create Object] -> pick [Player] sprite and create it on [Layer 0].
5. Move Layer 1 under Layer 0.
6. Notice the layer names don't change and the event sheet still says [Create Object] [Player] [On Layer 0].

You can also change the layer name to something else. Click the [Layer 0] and press [F2] on your keyboard to change the layer name to another name and see if that name would change after adding a new layer and put that layer underneath. It won't change. :D
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Tue Jan 31, 2017 5:51 pm

No, sanderstyler's right, it doesn't work, I'm working around by storing the game layer in a variable, and just referring to that every time, that way, no matter how many layers I add, I just can just update the variable.
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Wed Feb 01, 2017 4:33 am

Instead of referring to the layer number in your events, refer to the layer name.
The number changes based on order, the name doesn't.
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Wed Feb 01, 2017 8:12 am

spacedoubt wrote:Instead of referring to the layer number in your events, refer to the layer name.
The number changes based on order, the name doesn't.


So in the "layer" box in he create object dialog I just type the layer name? What if it conflicts with a variable or a system expression?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Wed Feb 01, 2017 9:20 am

This is addressed in the manual. https://www.scirra.com/manual/42/layers-bar

A number to the right. This is a zero based index of the layer (the first layer is number 0, not 1). If you need to enter a layer number in the event system, this is the corresponding number. (You can also enter layer names in the event system which might be more convenient if you regularly reorder layers.)


Some quick experimentation reveals that to refer to a layer by name, you would use quotation marks, while a variable or other expression with the same name can be referenced without quotation marks.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Wed Feb 01, 2017 9:24 am

oosyrag wrote:This is addressed in the manual. https://www.scirra.com/manual/42/layers-bar

A number to the right. This is a zero based index of the layer (the first layer is number 0, not 1). If you need to enter a layer number in the event system, this is the corresponding number. (You can also enter layer names in the event system which might be more convenient if you regularly reorder layers.)


Some quick experimentation reveals that to refer to a layer by name, you would use quotation marks, while a variable or other expression with the same name can be referenced without quotation marks.

Thanks, it wasn't immediately obvious, now I know.
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Wed Feb 01, 2017 9:46 pm

@Ashley maybe it could be worth considering changing the layer field default for the System-Create Object action (and others?) to be the name "Layer 0" rather than 0?

It would help in the situation where a user does significant work on their project, then decides to add a background or other layer beneath the initial one. Currently they would have to go back through all their events that created objects and update the layer field for each.

The second benefit would be for those who don't realize you can use layer names to reference the layer at all, as it really isn't immediately obvious.

I can't currently think of any situation where using the layer index would be preferable to the layer name.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests