Fading in and out an object (need for mini LD)

How to fade in/out sprite object using opacity? I need it for my MiniLD entry so it’s pretty urgent.

//edit: Nevermind, got help on LD channel. Proper equation is TimeDelta()*fadefactor, where fade factor is a fadefactor. Also depending on whether it is fade in or out, we substracting or adding this, respectively.

That is effectively the proper way to achieve a fade in/fade out. :slight_smile:

I am only able to fade out. What I want to do achieve is to start to start with opacity=0, then fade in and in the end fade out again.

I thought something like this should do the trick, but this does not work as I had hoped:

[attachment=0]opacity.png[/attachment]

It cannot work, as soon as the opacity is slighty modified is not 0 anymore ( or 100 ), nothing happens. And be careful, opacity is in the range [0, 255].
Use instead a variable to register the state where the object is.

[code]No conditions
Actions : Set opacity to 0
( Set Variable “OpacityState” of image to = 0 )

Conditions : Variable “OpacityState” of image is = 0
Actions : Do +30*TimeDelta() of opacity of image

Conditions : Opacity of image is = to 255
Actions : Set variable “OpacityState” of image to 1

Conditions : Variable “OpacityState” of image is = 1
Actions : Do -30*TimeDelta() of opacity of image[/code]

Thanks, that looks more like it. Something like this, right?

[attachment=0]opacity.png[/attachment]

However, it doesn’t seem to be doing anything in my case.

I’ve made a mistake in the first event :slight_smile:

Hmm, I fail to see it :slight_smile:

The first event is always setting variable “opacitystate” to 0. It should be done only once ( At the beginning of the scene or from time to time to relaunch the fading in and out, but not always ).

Oceldot, go and download sources. Game is called “Dragon’s Story”.

In any case, it should work perfectly with the events provided the first one is corrected ( by adding a “At the beginning of the scene” condition or by removing the second action ).

It works fine when adding the At the beginning of scene condition. Not sure I understand why that was necessary though. Anyway, thanks a lot :slight_smile:

Some great use of fading in Dragon’s Stoy, Darkhog. What is this LD thing?

The variable is here to store if the object is fading in or fading out.
If you reset the variable to 0 each time events are launched, it cannot obviously do what it is meant for.

Just try to execute yourself the events “in your head” ( or with a pen and some paper : Start with variable to 0, “execute” the events one after one, then do it again, again, and then assume that opacity reach 255 ( Events are executed a lot of time per seconds, so the opacity does not reach 255 immediatly! ) and then “execute” again the events one after one. ), and I’ll see that if you do not add the condition, the variable will always be 0, and so the 4th event won’t be executed. :slight_smile: