I am making a game using libGDX and Tween Universal Engine.
My problem is as follows:
I have 2 screens so fars, a splash screen with the logo, and a second one which is the main menu.
In the splash screen I use a SpriteBatch
and a Sprite
with the Texture
of the image I want (which goes through some scaling.)
Now I use the Tween engine, along with a created SpriteAccessor
to control the alpha of the sprite. I fade the picture in, then fade it out, then change it to the next screen.
In the next screen I have a single sprite, and a single, 3 slot, sprite array. In this screen I also use the tween engine, I fade the single sprite into the screen (it's the background image) then I try to, using the same method, (Tween.to
) to change the alpah of the sprite array (each sprite by itself.), I first set it to 0 using Tween.set
, then using the method I change it.
This didn't work, after some tests I tried setting the alpha of a single sprite from the array to 0, and that didn't work.
It's like the program is ignoring the alpha value, I even printed out the alpha value, it saying 0, but the sprite is visible.
How can I fix this, or why might it be caused?
1 Answer
I just had the same problem
This is my solution
public class SpriteAccessor implements TweenAccessor<Sprite> {
public static final int ALPHA = 1;
@Override
public int getValues(Sprite sprite, int tweenType, float[] returnValues) {
switch (tweenType) {
case ALPHA: {
returnValues[0] = sprite.getColor().a;
return 1;
}
default: {
assert false;
return -1;
}
}
}
@Override
public void setValues(Sprite sprite, int tweenType, float[] newValues) {
switch (tweenType) {
case ALPHA: {
sprite.setAlpha(newValues[0]);
break;
}
default: {
assert false;
break;
}
}
}
}
GameScreen class setup tweening after registering accessor and instantiate TweenManager
Tween.set(Art.nextButton, SpriteAccessor.ALPHA).target(0.5f).start(mTweenManager);
Tween.to(Art.nextButton, SpriteAccessor.ALPHA, 1.0f)
.target(1.0f)
.repeatYoyo(10, 0.2f)
.start(mTweenManager);
GameScreen class render loop
mTweenManager.update(Gdx.graphics.getDeltaTime());
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();
Art.nextButton.draw(spriteBatch);
spriteBatch.end();
SpriteBatch.enableBlending()
andSpriteBatch.setBlendFunction()
\$\endgroup\$