简体   繁体   中英

LibGdx:Tween Callback on Tween Engine

I am following the following tutorial I have created a button but now when i write the TweenCallback it should display the button at the end of the animation. However it is not working and just ends up with the splash screen fading in and out. This is my code for the splash screen.

public class Splash implements Screen{
private Sprite splash;
private SpriteBatch batch;
private TweenManager tweenManager;

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    tweenManager.update(delta);
    batch.begin();
    splash.draw(batch);
    batch.end();

}

@Override
public void resize(int width, int height) {

}

@Override
public void show() {
    tweenManager = new TweenManager();
    Tween.registerAccessor(Sprite.class, new SpriteAccessor());
    batch = new SpriteBatch();
    Texture splashTexture = new Texture ("Backgrounds/openingScreen.png");
    splash = new Sprite(splashTexture);
    splash.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Tween.set(splash, SpriteAccessor.ALPHA).target(0).start(tweenManager);
    Tween.to(splash, SpriteAccessor.ALPHA, 3f).target(1).repeatYoyo(1, 0f).setCallback(new TweenCallback() {

        @Override
        public void onEvent(int type, BaseTween<?> source) {
            ((Game)Gdx.app.getApplicationListener()).setScreen(new MainMenu());
        }
    }).start(tweenManager);
}

I know the problem is not with the button as i have in my main class tried to use setScreen (new MainMenu()); and the button shows up. Now here i dont understand why it wont show up. The tutorial works fine and i also checked my code against the source code from the tutorial. Any ideas? Thanks

答案:原来我已经注释掉MainMenu类中屏幕上的初始绘制,这就是为什么它不起作用的原因

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM