我试图让启动画面等待10秒钟 我尝试到处搜索并尝试了一些方法,但似乎没有任何工作。
任何人都能引导我走向正确的方向吗?
这是我的代码:
public class SplashLoadingScreen extends Screen {
public SplashLoadingScreen(Game game) {
super(game);
}
@Override
public void update(float deltaTime) {
Graphics g = game.getGraphics();
Assets.splash= g.newImage("splash.jpg", ImageFormat.RGB565);
game.setScreen(new LoadingScreen(game));
}
@Override
public void paint(float deltaTime) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
@Override
public void backButton() {
}
}
答案 0 :(得分:1)
尝试使用Handler来延迟。
//handler to close the splash activity after sometime
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Call your image from assests
}
}, 10000);
希望这有帮助。
由于
答案 1 :(得分:0)
与my answer here类似,您应该使用update
方法更新将启动屏幕更改的计时器。
public class SplashLoadingScreen extends Screen {
private Sprite sprite;
private Texture texture;
public SplashLoadingScreen(Game game) {
super(game);
texture = new Texture(Gdx.files.internal("data/splash.png");
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite = new Sprite(new TextureRegion(texture, 0, 0, imageWidth, imageHeight);
}
private float timer = 0.0f;
@Override
public void update(float deltaTime) {
timer += deltaTime;
if(timer > 10) {
game.setScreen(new LoadingScreen(game));
}
}
@Override
public void paint(float deltaTime) {
spriteBatch.draw(sprite);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
texture.dispose();
}
@Override
public void backButton() {
}
}
答案 2 :(得分:-1)
public class SplashLoadingScreen extends Screen {
public SplashLoadingScreen(Game game) {
super(game);
}
@Override
public void update(float deltaTime) {
Graphics g = game.getGraphics();
Assets.splash= g.newImage("splash.jpg", ImageFormat.RGB565);
try {
Thread.currentThread();
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
game.setScreen(new LoadingScreen(game));
}
@Override
public void paint(float deltaTime) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}