我正在 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
因为你splashImg
是空当你设置的起源oneImg
Image
。
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
Lifecycle 中调用一次的东西,当时计数器有 10 个值,所以你的Actor
oneImg、twoImg 和 splashImg 不会添加到阶段。在Screen
Lifecyclerender()
之后调用show()
。
if (counter==3){
stage.addActor(oneImg);
}
else if(counter==2){
stage.addActor(twoImg);
}
else if(counter==1){
stage.addActor(splashImg);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句