我正在 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);
}
}
最佳答案
您遇到了 NullPointerException
,因为当您设置 oneImg
Image
的原点时,您的 splashImg
为 null。
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
生命周期中调用一次,并且计数器当时的值为 10,因此您的 Actor
oneImg、twoImg 和splashImg 将不会添加到舞台中。在 Screen
生命周期 render()
中,在 show()
之后调用。
if (counter==3){
stage.addActor(oneImg);
}
else if(counter==2){
stage.addActor(twoImg);
}
else if(counter==1){
stage.addActor(splashImg);
}
关于java - 如何使用libgdx在一个舞台上连续显示三个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43557248/