How do I change fade-behaviour values via an action?

0 favourites
  • 5 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • How do I change fade-behaviour values via an action?

    I want to change the fade out time via an action, in the event sheet.

    Why not in the properties bar of the fade-behaviour? Because a lot of sprites are going to be faded out and I want the fade out time to change during the game.

    I expected to find something like:

    action --> sprite.fade.fadeouttime = x

    But the sprite that has the fade behaviour only shows 2 fade-actions in the event sheet:

    • restart fade
    • start fade
  • I don't think you can do it with the Fade behavior.

    Use opacity with events:

    Add an instance Boolean Variable to your object( i'll name the object "myOpaqueObject"), for example "opaque" and set the default value to true

    Add an instance Number Variable, for example "FadingTime" and set its value to something appropriate (I'll use 120).

    In the event sheet create two conditions that check and decide if the object should be opaque or not.

    For example:

    If myOpaqueObject is overlaping with "something" ===>myOpaqueObject | Set opaque to True

    If myOpaqueObject is not overlaping with "something" ===>myOpaqueObject | Set opaque to False

    Then add the events that will control the fading, depending on the booleans true/false state:

    If myOpaqueObject is opaque ===> myOpaqueObject |set opacity to self.Opacity + 1 * FadingTime * dt

    If myOpaqueObject is not opaque ===>myOpaqueObject | set opacity to self.Opacity - 1 * FadingTime * dt

    By multiplying with 120 and dt you are ensuring that the fade will last 2 seconds regardless the frame rate of the game. Use multiples of 60 for every second you wish to add (for example 60*dt will last 1 second, 120*dt will last 2 seconds, 180*dt =3 seconds and so forth...) You can effectively control the FadingTime with events (actions/instance variables/set value) to change the fading time.

  • Check out the LiteTween behavior here in the Behaviors section, tween the "opacity" of your objects/family and you should be set -- there are lots of "easing" functions to get some neat effects too.

    Once you start tweening, you can't stop

    Hope this helps.

    -Remy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the useful replies.

    I've added eli0s ' text as a private tutorial on my computer and I am going to try out remy-jay 's tip.

  • Thanks for the useful replies.

    I've added eli0s ' text as a private tutorial on my computer and I am going to try out remy-jay 's tip.

    Urr, I messed up the dt to seconds translation. 100 * dt = 1 sec, 200 * dt = 0.5 seconds and 50 * dt is 2 seconds. In my previews post I am way off.

    Basically dt ensures that you get real time results no mater the frame rate, in our case, we want to add or subtract a value of 100 (the maximum opacity) so by multiplying +/-100 with dt we get a value change of 100 within one second. The dt is like a constant, so for half a second fade we say add (or remove) the value of 200 in dt time, but since our maximum value is 100 the result is getting a 100 value (or 0) in half a second...

    Here is an example capx which basically does the fading with on mouse over/mouse out events.

    http://www.eli0s.com/Tests/Fades.capx

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