Animate sprite opacity (SOLVED)

I’m trying to do smooth screen transitions using fade in/out… Is it possible to animate the opacity of a collection/game object/sprite? I know I can set a sprite’s opacity by doing:

sprite.set_constant(target, "tint", vmath.vector4(1, 1, 1, 0.5))

But I haven’t seen the equivalent to gui.animate or go.animate.

2 Likes

EDIT:

Yes, you can animate these properties:

	go.animate("#sprite", "tint.w", go.PLAYBACK_LOOP_PINGPONG, 0, go.EASING_INOUTSINE, 2)
7 Likes

I was totally wrong in my prev answer. See edit above! :slight_smile:

2 Likes

Awesome! Thank you so much!

1 Like

Hey there,

I’m wondering: Is there somewhere in the API reference where we could have found that??

Thanks,

K

1 Like

It is mentioned in the Properties manual but it should be made clearer. See http://www.defold.com/manuals/properties/

2 Likes

Excellent!

But how do you restore it? :confused:

I mean, how do you stop blinking and continue normal, full visible? :relaxed:

Try this:

go.cancel_animations("#sprite", "tint.w")
go.set("#sprite", "tint.w", 1.0)

Another short non-looping animation to go back to 1 will look nicer.

5 Likes

Excellent! That did it! :ok_hand:

Thank you Ragnar! :thumbsup:

Sorry to revive an old thread.

What does the w in “tint.w” mean and what other tint properties are there? (i am interested in the alpha channel and tint.w seems to be fading the colour to white)

got it. x, y, z, w for r, g, b, a.

2 Likes

“tint” is a shader constant which is defined for the builtin material you use to draw sprites. You can change that of course. .w is the fourth component of that value, as in .x, .y, .z, .w. This means that .w does whatever the shader implements it to do, in this case be multiplied onto the fourth color component, which happens to define transparency for blending.
In other words “tint” is not a part of the engine, it’s a part of the builtin content we ship with it. All of this also means that you can change the values to whatever you need if you choose to have a different lighting model.

3 Likes

In my case tint.w doesn’t change the alpha channel, just makes the sprite darker.

go.set("#sprite", "tint.w", 0.0)

Oh nvm my bad, I was using -2 as value of the z vector.

3 Likes