Change tween sprite and restart the tween
So I have a splash screen which displays an image and then fades out,
displays a second image and fades out. However the code is very redundant.
private void startFirstTween() {
splashSprite = new Sprite(new Texture(
"imgs/picOne.png"));
splashSprite.setSize(Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
splashSprite.setColor(1, 1, 1, 0);
TweenCallback cb = new TweenCallback() {
@Override
public void onEvent(int type, BaseTween<?> source) {
firstCompleted();
}
};
Tween.to(splashSprite, SpriteTween.ALPHA, 1.5f).target(1)
.ease(TweenEquations.easeInQuad).repeatYoyo(1, 1.5f)
.setCallback(cb)
.setCallbackTriggers(TweenCallback.COMPLETE)
.start(manager);
}
private void firstCompleted() {
startSecondTween();
}
private void startSecondTween() {
splashSprite = new Sprite(new Texture("imgs/picTwo.png"));
splashSprite.setSize(Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
splashSprite.setColor(1, 1, 1, 0);
TweenCallback cb = new TweenCallback() {
@Override
public void onEvent(int type, BaseTween<?> source) {
secondCompleted();
}
};
Tween.to(splashSprite, SpriteTween.ALPHA, 1.5f).target(1)
.ease(TweenEquations.easeInQuad).repeatYoyo(1, 1.5f)
.setCallback(cb)
.setCallbackTriggers(TweenCallback.COMPLETE)
.start(manager);
}
private void secondCompleted() {
game.setScreen(new StartScreen(game));
}
As you can see, all that changes is that the image for the sprite changes.
Is there a way I can change the sprite and then "restart" the tween?
No comments:
Post a Comment