我目前有2个类,一个Assets类和一个加载屏幕类: 资产类:
public class Assets {
public static AssetManager manager = new AssetManager();
public static void queueLoading() {
(..)
manager.load("sound/startScreen.mp3", Music.class);
(..)
while(!manager.update())
{
System.out.println("Loaded: " + manager.getProgress() *100 + "%");
}
}
public static boolean isLoaded() {
if(manager.getProgress() >= 1)
return true;
return false;
//return manager.update();
}
}
加载屏幕::
public class LoadingScreen implements Screen{
final Game1 game;
Sprite LdScreen;
OrthographicCamera camera;
public LoadingScreen(Game1 gam){
game=gam;
camera = new OrthographicCamera();
camera.setToOrtho(false, 1920, 1080);
}
public void show() {
Texture LdscreenTexture = new Texture(Gdx.files.internal("data/Background.png"));
LdScreen = new Sprite (LdscreenTexture);
}
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game.batch.setProjectionMatrix(camera.combined);
game.batch.begin();
game.batch.draw(LdScreen, 0,0);
game.batch.end();
Assets.manager.update();
if(Assets.manager.update() == true){
game.setScreen(new MainMenuScreen(game));
System.out.print("test");
}
}
问题是这不起作用,当我立即运行时Assets.manager.update
返回true并且我收到一条错误消息,指出找不到MainMenuScreen
的资产,因为它们尚未加载。当我注释掉game.setScreen(new MainMenuScreen(game));
时,我将'test'写入控制台但我没有从Assets类中获得进入控制台的进度。这让我想到,当我运行时,Asset.smanager.update
总是返回true,而且根本没有加载资产。
我看过教程和维基,但我没有发现它们有用。有什么想法吗?