2017-04-22 74 views
1

我在libgdx创建一个启动画面显示在舞台连续三张图片,所以我需要显示连续三幅图像,以我的舞台如何使用libgdx

private float time; 
private int counter=10; 

public void update(float delta) { 

    stage.act(delta); 
    counter-=Gdx.graphics.getRawDeltaTime(); 
    counter-=delta; 
    if (counter==3) 
    { 
     stage.addActor(oneImg); 
    } 
    else if(counter==2) 
    { 
     stage.addActor(twoImg); 
    } 
    else if(counter==1) 
    { 
     stage.addActor(splashImg); 
    } 
} 
+0

你在调用'stage.draw()'吗?当然,我没有,但有一些不顺心E/AndroidRuntime的 – Aryan

+0

:致命异常:GLThread 23278 显示java.lang.NullPointerException –

+0

你的代码是不够的,找出你的异常,并请张贴完整的logcat错误 – Aryan

回答

0

您已经NullPointerException因为你splashImg为空当你设置的起点为oneImgImage

Texture one = new Texture(Gdx.files.internal("img/one.png")); 
oneImg = new Image(one); 
oneImg.setOrigin(splashImg.getWidth()/2, splashImg.getHeight()/2); // splashImag is null here 

还有一件事show()Screen生命周期调用一次,在那个时候让你Actor oneImg,twoImg和splashImg不会加入到舞台有10值计数器。在Screen生命周期render()之后调用show()

if (counter==3){ 
    stage.addActor(oneImg); 
} 
else if(counter==2){ 
    stage.addActor(twoImg); 
} 
else if(counter==1){ 
    stage.addActor(splashImg); 
}