尝试创建加载屏幕,我有一个Assets
类和一个LoadingScreen
类,可以立即调用:
this.setScreen(new LoadingScreen(this));
在加载屏幕上,我有这个:
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);
Assets.manager.finishLoading();
}
@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));
}
}
但是它总是返回并且出错,好像它试图转移到MainMenuScreen
类并且资源没有被加载,如果Assets.manager.update()
为真,它应该是正确的吗?
为什么这是一个问题?
答案 0 :(得分:2)
这个简单的例子
.//加入您的Class Game1
变量类
private AssetManager yourAssetManager;
创建方法
yourAssetManager = new AssetManager();
获取设置方法
public AssetManger getManger(){
return this.yourAssetManager;
}
public class LoadingScreen implements Screen{
final Game1 game;
Sprite LdScreen;
OrthographicCamera camera;
AssetManager yourAssetManager;
public LoadingScreen(Game1 gam){
game=gam;
this.yourAssetManager = game.getManager();
camera = new OrthographicCamera();
camera.setToOrtho(false, 1920, 1080);
}
public void show() {
使用yourAssetManager.load(....用于加载资产
yourAssetManager.load("data/Background.png", Texture.class);
Texture LdscreenTexture = new Texture(Gdx.files.internal("data/Background.png"));
LdScreen = new Sprite (LdscreenTexture);
//Assets.manager.finishLoading();
}
@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(yourAssetManger.update()){
game.setScreen(new MainMenuScreen(game));
}
}
阅读此链接https://github.com/libgdx/libgdx/wiki/Managing-your-assets我,我现在不测试抱歉。