我正在编写libgdx游戏,但是在游戏启动后并没有立即显示启动屏幕。我正在使用资产管理器在后台加载资源。有谁知道这是怎么回事? 游戏启动时,它只会显示黑屏,然后在内存中加载资产5-6秒后,它会显示启动屏幕一秒钟,然后显示主屏幕。
这是我的课程。
public class SplashScreen implements Screen {
private SpriteBatch batch;
private Texture logo;
private BabyGame game;
private MyAssetManager myAssetManager;
public SplashScreen(BabyGame game) {
this.game = game;
myAssetManager = new MyAssetManager();
}
@Override
public void show() {
batch = new SpriteBatch();
logo = new Texture("bg.png");
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.8f, 0.8f, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(logo,0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
batch.end();
if (myAssetManager.update())
game.setScreen(new BabyOrange(game));
}
这是游戏课
public class BabyGame extends Game
{
AdService adService;
MyAssetManager assetManager;
public BabyGame(){
assetManager = new MyAssetManager();
}
@Override
public void create() {
setScreen(new SplashScreen(this));
}
}
和资产类别
public class MyAssetManager {
public AssetManager manager;
public MyAssetManager(){
manager = new AssetManager();
}
public void load(){
manager.load("background-orange.png",Texture.class);
manager.load("orange-phone.png",Texture.class);
manager.load("buttons.txt", TextureAtlas.class);
manager.load("bgAudio.mp3", Music.class);
manager.finishLoading();
}
public boolean update(){
return manager.update();
}
}
答案 0 :(得分:0)
You can add Handler() Method in :
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this,MainActivity.class));
finish();
}
}, 1000);
And also please check the size of the images.