2015-04-04 107 views
0

我想讓啓動屏幕等待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() { 
} 
} 
+2

10秒似乎很長一段時間來等待沒有理由 – cYrixmorten 2015-04-04 14:29:58

+0

真實的,但我需要它10秒工作... – 2015-04-06 02:32:12

+0

十秒長的離譜。每次開始遊戲時,我都不會玩等待10秒的遊戲。 4秒更有意義。每當我做出啓動畫面時,我都會將它設置爲可點擊的,以便您可以通過它。 – EpicPandaForce 2015-04-09 07:28:42

回答

1

嘗試。

//handler to close the splash activity after sometime 
     new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 
       //Call your image from assests 
      } 

     }, 10000); 

希望這會有所幫助。

感謝

+0

處理程序是Android特定的,此代碼是爲libGDX(純java) – EpicPandaForce 2015-04-09 07:30:02

-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() { 
} 
} 
+0

我的應用程序崩潰時,我使用的代碼你寫道.. – 2015-04-04 23:12:04

+0

這似乎工作..但由於某種原因,等待工作在黑屏出現之前splash.jpg屏幕 – 2015-04-05 07:57:12

+0

**不要等待10秒的主線程** – EpicPandaForce 2015-04-09 07:27:25

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() { 
} 
} 
+0

當我嘗試使用該代碼例如..我得到錯誤..後我導入一切,並添加gdx。我在spriteBatch.draw(sprite)中得到錯誤;任何想法我應該做什麼? – 2015-04-11 23:38:59

+0

是的,你需要初始化'spriteBatch' **某處** – EpicPandaForce 2015-04-12 00:20:21

+0

我想你已經想出瞭如何*在初始屏幕上繪製圖像*,因爲你需要一個精靈批處理。 – EpicPandaForce 2015-04-12 00:58:33