A Specific Tweening Scenario (LibGDX)

Hello everyone, first post here. I rarely ever seek advice but I figured I’d try it out!

I have a cave situation where I would like to set a dark overlay onto my whole cave scene with a float amount of alpha to simulate a dark cave appearance - CHECK

Next I have spike objects that I’d like to tween in and out of full alpha visibility “through” this darkness. Any tips on how to set something like this up? Appreciate the input!

Copied from the other thread in case it gets deleted: (this is the correct place now)

It’s fairly easy to homebrew that, simply have the spike be “Updatable” or otherwise hooked in to the game loop somehow, and on each update set the alpha to the value given by some function of time, a sine curve for example.


private double totalTime = 0;

public void update(double delta) { // can be done without variable timestep as well
    totalTime += delta;
    setAlpha(Math.sin(totalTime) / 2 + .5); // normalize the sin() to the range [0, 1]
}

You can use the fantastic Desmos online graphing calculator to figure out some good functions.

You might want to check out the Universal Tween Engine, which integrates into libGDX quite well.

Scene2d.ui Actors also have some built-in tweening options as well with the Actions factory methods.

Looks like everything is here that’s in the old thread, so I just removed it.

Ah, great response. I like the curve idea and will be using it! Sorry I wasn’t entirely specific because I am using the Universal Tween Engine and have it ready to go for the situation. I’m mainly curious what the best route would be to make the appearance of an object being behind an alpha black overlay (which is set at about .5 alpha) and coming to the front. All the while background elements are still faintly visible the whole time. I want the spikes be barely visible like the rest of the background elements before being brought to the front.

With my lack of experience, the only way could picture doing this doesn’t seem like the right way. It would involve having spikes on the foreground above the dark overlay and bringing them from say .2 alpha to 1. Mentally picturing this, It doesn’t seem it would look right.

So curious if there is a way to bring them from being actually behind the overlay, or at least have the proper appearance of it, and into the front. Perhaps I might need to make all elements a bit transparent for what I’m going for? I’ll have to actually experiment before I go any further. Thanks!

If the overlay is static (doesn’t change in alpha, color, etc.), then I would just tint the spike sprite the same color as the overlay and draw it over the overlay, tweening the tint darkness.
Actually it would even work for a changing overlay, so ignore the first part of that sentence, just have the tint color be a function of the current overlay color and a darkness “offset,” which is controlled by the sine function.

This is great, I will have to try this out. Thank you!