Fade out upper layer while moving down layers

0 favourites
  • 15 posts
From the Asset Store
Set of tiles to create a map for top-down games with island theme
  • 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?

  • How's this for a start? It fades out all layers above the current layer: fadeOutLayers.capx (r146)

  • 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!)

  • 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?

  • 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:

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/changeLayer.PNG" border="0" />

    That works better.

  • ramones - Okay, I think I'm following you. I'll check back if I need further clarification. Thanks. :)

  • 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?

  • 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.

  • ramones - Thank you, sir. :) That does clear things up.

  • 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 , ArcadEd, Arima, BlueBlaze, or ? Heh, just someone who can spare a moment since ramones has already given me much of his.)

  • I hadn't considered layers between floors. Ok so new plan. I made an array called "FloorNames" that holds the names of the floor layers.

    The function ChangeFloor(direction) is called with the parameter "up" or "down". It gets the index of the current floor in the array. If param(0) = "up" and you're not on the top floor then it calls the function ChangeLayer("layerName") with the name of the next floor in the array.

    If param(0) = "down" and you're not on the bottom floor then it calls ChangeLayer("layerName") with the name of the previous floor in the array.

    The ChangeLayer("layername") function moves the player to the layer given and activates the fade group.

    And then the FadeTopFloors group loops through the array and fades the layers that come after the current layer.

    I don't know if this is easier or harder to understand.


  • ramones - Well, your explanation made sense. I'll try to follow along in the capx, itself. Thank you once again, sir! (I think I'm gonna have to give you SEVERAL slots-worth in the post-game credits. LOL)

  • Looks good! Except now the layers, themselves don't scale...just the CharFinn object. I'll look over it, but maybe you can see what happened?

  • Ahh change CurrentLayerScaleValue to LayerScale(CharFinn.LayerName) in event 17.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ramones - Dude, I can't wait to have insight like you do. I'm slowly getting the hang of reading C2 like it's nothing, but THINKING in C2, that's still another story. Thank you again!

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