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

Get help using Construct 2

Post » Mon Mar 31, 2014 9:37 pm

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
B
27
S
6
G
7
Posts: 678
Reputation: 5,651

Post » Mon Mar 31, 2014 10:34 pm

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.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Tue Apr 01, 2014 1:52 am

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
B
72
S
14
G
1
Posts: 151
Reputation: 4,999

Post » Tue Apr 01, 2014 8:26 pm

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.
B
27
S
6
G
7
Posts: 678
Reputation: 5,651

Post » Tue Apr 01, 2014 11:09 pm

rogerty wrote: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
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests