Fade out upper layer while moving down layers

Get help using Construct 2

Post » Sun Oct 06, 2013 7:27 am

CAPX: https://www.sugarsync.com/pf/D6025908_4317202_6933785

Pressing the 1 or 2 keys will cause all the layers to scale in or out (imagine this is a top-down view, and each layer is a floor in a building). What I'm trying to do is make it so that each floor above the floor that the black block is on will fade out as so not to obstruct what's going on below it.

I've tried several different methods, including the For loop, where I subtract 10 from the layer opacity for every iteration of the loop, and I've tried using the Fade behavior, and a couple of other deals. Nothing's quite working.

Presently, the attempt is the make the layer fade based on a percentage of a target opacity value. As you can see, the blue layer is close to what I have in mind as the scale adjusts. But it's working at the wrong time.

Both Layer 1 and Layer 2 should be opacity 0 at start. Any layer the black block is on and any layer below it should be visible. Moving down a layer (aka floor) will cause the former layer to fade out and layers farther above will be invisible.

Any suggestions, please?
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
135
S
22
G
8
Posts: 770
Reputation: 14,689

Post » Sun Oct 06, 2013 3:05 pm

How's this for a start? It fades out all layers above the current layer: fadeOutLayers.capx (r146)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Mon Oct 07, 2013 3:57 am

@ramones - DUDE!!! That's beautiful! Thank you so much! :D I'll tweak it to fit my liking and work to understand exactly what you did, but man, I so appreciate your time on this. (I may seem to be getting extra-happy about it, but it means so much to me...I have BIG goals I'm working towards, starting with this game. So you're helping me keep my goals alive. Again, THANK you!)
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
135
S
22
G
8
Posts: 770
Reputation: 14,689

Post » Mon Oct 07, 2013 8:31 am

@ramones - Thank you again for your help.
I was wondering if you could help me break down your additions. I'm not yet fully adept at using the Function object.
Particularly, on line 7, you have the action Set currentLayer to Function.Param(0). But I see that in each instance that you make a Call to the functions, you have a min or max parameter. Why the "0" in line 7?
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
135
S
22
G
8
Posts: 770
Reputation: 14,689

Post » Mon Oct 07, 2013 3:00 pm

Function.Param(0) is the first parameter. Function.Param(1) is the second etc...

If you're on layer 2 and you press '1' then it calls the function: changeLayer(1).
Function.Param(0) = 1.
So currentLayer is set to 1.

The min() and max() were there to prevent the number going below 0 or above numLayers-1.
I just changed it to this instead:

That works better.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Mon Oct 07, 2013 9:36 pm

@ramones - Okay, I think I'm following you. I'll check back if I need further clarification. Thanks. :)
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
135
S
22
G
8
Posts: 770
Reputation: 14,689

Post » Mon Oct 07, 2013 10:24 pm

@ramones - Okay...just to confirm...

numLayers never changes - it's a constant (at value 3), correct?
currentLayer is to denote - as the name implies - the CURRENT layer that the Sprite object is on.

In the FadeTopLayers group, layers refers to any layer above the current layer (per line 9's action).
Variable finished checks to see when the fading of a layer is complete, but I don't see any time when its value is actually set to "true"... Does that have to do with the fact that it's not constant nor static and that it's repeatedly set to "false" within the While loop?
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
135
S
22
G
8
Posts: 770
Reputation: 14,689

Post » Mon Oct 07, 2013 11:54 pm

finished starts off as "true". It's a local variable so it's value is reset (to "true") every tick.

Then inside the loop - if the opacity of any layer (above currentLayer) is > 0 then finished is set to "false".

If finished is still equal to "true" after the loop ends then that means that all layers (above currentLayer) have 0 opacity so the group is deactivated.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Tue Oct 08, 2013 7:16 am

@ramones - Thank you, sir. :) That does clear things up.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
135
S
22
G
8
Posts: 770
Reputation: 14,689

Post » Wed Oct 09, 2013 4:04 am

MAIN CAPX: https://www.sugarsync.com/pf/D6025908_4317202_6930991

TEST CAPX: https://www.sugarsync.com/pf/D6025908_4317202_6933785

Alrighty! Next issue.
In the main capx, I adapted everything you helped set me up with. In your rendition, we have 3 layers to work with - 0 through 2. But in my main capx, I have a few other layers, namely the Effects layer, which is nestled between Ground and Floor2

So with that in mind, I created a new Function, "LayerNames" (see line 13 and line 12 for the Call action), to adapt the placement of the CharFinn object based on the value of CurrentLayer.

However, this isn't working, and I just don't understand why. I'm still struggling to grasp the parameters element of the functions, as well, which is probably ALSO why it's not working. (In another file, I tried swapping lines 9 and 11, thinking I had them in the wrong spots. Still no dice.)

I need a recap on the function parameters, too.
Here's the way I'm understanding them...

Let's say you're the "Ground" layer... 0.
So CharFinn collides with the StairsUp object...the Function kicks in:

Call ChangeLayer(min(NumberOfLayers-1, CurrentLayer+1))

Number of layers is 3 and the current layer is 0.

Call ChangeLayer(min(2,1))

So the minimum value is 1, and thus goes up to "Floor2" (per my additional Function).

Thanks again for your time.

(Alternatively, if you're busy, may I petition help from @squiddster, @ArcadEd, @Arima, @Blueblaze, or @TeamNotion? Heh, just someone who can spare a moment since @ramones has already given me much of his.)Rhindon2013-10-09 04:06:24
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
135
S
22
G
8
Posts: 770
Reputation: 14,689

Next

Return to How do I....?

Who is online

Users browsing this forum: jkmalau, MoscowModder, terence951, vegapomme27 and 9 guests