我需要知道如何从纹理图集中添加一个精灵,以便我可以将它实现为我的主菜单的精灵。
这是我的主菜单代码:
public class MainMenu implements Screen {
CrazyZombies game;
Stage stage;
TextureAtlas atlas;
Skin skin;
SpriteBatch batch;
TextureRegion firstLayer;
TextureRegion secondLayer;
TextureRegion thirdLayer;
TextureRegion fourthLayer;
TextureRegion fifthLayer;
TextureRegion sixthLayer;
TextureRegion seventhLayer;
TextureRegion eighthLayer;
TextureRegion ninthLayer;
TextureRegion tenthLayer;
TextureRegion eleventhLayer;
public MainMenu(CrazyZombies game){
this.game = game;
}
@Override
public void render(float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(0.09f, 0.28f, 0.2f, 1);
batch.begin();
batch.end();
}
@Override
public void resize(int width, int height) {
Gdx.input.setInputProcessor(stage);
}
@Override
public void show() {
batch = new SpriteBatch();
skin = new Skin();
}
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
batch.dispose();
skin.dispose();
atlas.dispose();
stage.dispose();
}
public void loadLayers() {
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/mainmenu/MainMenu.pack"));
firstLayer = atlas.findRegion("1layer");
}
}
所以我需要着手让 firstLayer 出现在屏幕上,而我尝试过的每一种方式都以崩溃告终。