我为我的Libgdx
游戏创建了多个Screen
。
每当我退出游戏(桌面版)时,我都会在 eclipse 控制台中收到一个红色句子,显示Deleting Buffers(1)
。
该数字根据Screen
而变化,当我退出游戏时,该处于活动状态。
这是什么"删除缓冲区"?
我有必要担心吗?
此外,我的游戏的安卓版本在第二个Screen
崩溃,而桌面版本运行良好。
提前谢谢。屏幕1
public class Splash implements Screen {
private SpriteBatch batch;
private Sprite titleSprite;
private Input input;
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
batch.begin();
titleSprite.draw(batch);
batch.end();
Gdx.input.setInputProcessor(input);
}
@Override
public void show() {
batch = new SpriteBatch();
titleSprite = new Sprite(new Texture("img/Title.jpg"));
titleSprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
titleSprite.setOrigin(titleSprite.getWidth() / 2f,
titleSprite.getHeight() / 2f);
titleSprite.setPosition(
Gdx.graphics.getWidth() / 2f - titleSprite.getWidth() / 2f,
Gdx.graphics.getHeight() / 2f - titleSprite.getHeight() / 2f);
input = new Input() {
public boolean keyDown(int keycode) {
if (keycode == Keys.ENTER) {
((Game) Gdx.app.getApplicationListener())
.setScreen(new MainMenu());
Gdx.audio.newMusic(Gdx.files.internal("sounds/button.mp3"))
.play();
dispose();
}
if (keycode == Keys.ESCAPE) {
Gdx.app.exit();
}
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer,
int button) {
((Game) Gdx.app.getApplicationListener())
.setScreen(new MainMenu());
dispose();
return super.touchDown(screenX, screenY, pointer, button);
}
};
}
@Override
public void dispose() {
batch.dispose();
titleSprite.getTexture().dispose();
}
}
屏幕2
public class MainMenu implements Screen {
private Stage stage;
private Table table;
private TextButton playButton, exitButton;
private Skin skin;
private BitmapFont white, black;
private TextureAtlas atlas;
private TextButtonStyle textButtonStyle;
private SpriteBatch batch;
private Sprite sprite;
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
batch.begin();
sprite.draw(batch);
batch.end();
stage.act(delta);
stage.draw();
Gdx.input.setInputProcessor(stage);
if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
Gdx.app.exit();
}
}
@Override
public void show() {
batch = new SpriteBatch();
sprite = new Sprite(new Texture("img/Title.jpg"));
sprite.setOrigin(sprite.getWidth() / 2f, sprite.getHeight() / 2f);
sprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
sprite.setPosition(Gdx.graphics.getWidth() / 2f - sprite.getWidth()
/ 2f, Gdx.graphics.getHeight() / 2f - sprite.getHeight() / 2f);
sprite.setRotation(0);
white = new BitmapFont(Gdx.files.internal("fonts/White.fnt"), false);
black = new BitmapFont(Gdx.files.internal("fonts/Black.fnt"), false);
black.setScale(Gdx.graphics.getWidth() / 1440f,
Gdx.graphics.getHeight() / 900f);
stage = new Stage();
atlas = new TextureAtlas("ui/Button.pack");
skin = new Skin(atlas);
table = new Table(skin);
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.getDrawable("ButtonUp9");
textButtonStyle.down = skin.getDrawable("ButtonDown9");
textButtonStyle.pressedOffsetX = 1;
textButtonStyle.pressedOffsetY = -1;
textButtonStyle.font = black;
exitButton = new TextButton("Exit", textButtonStyle);
exitButton.pad(10);
playButton = new TextButton("Play", textButtonStyle);
playButton.pad(10);
playButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener())
.setScreen(new Scenarios());
Gdx.audio.newSound(Gdx.files.internal("sounds/button.mp3"))
.play(1);
Gdx.input.vibrate(50);
dispose();
}
});
exitButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit();
dispose();
}
});
table.add(playButton);
table.row();
table.add(exitButton);
table.getCell(exitButton).spaceTop(50f);
stage.addActor(table);
}
@Override
public void dispose() {
stage.dispose();
black.dispose();
white.dispose();
skin.dispose();
batch.dispose();
sprite.getTexture().dispose();
}
}
屏幕3
public class Scenarios implements Screen {
private TextButtonStyle buttonStyle;
private TextButton[] scene;
private BitmapFont black;
private Stage stage;
private Table table;
private TextureAtlas atlas;
private Skin skin;
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
Gdx.input.setInputProcessor(stage);
if (Gdx.input.isKeyPressed(Keys.BACKSPACE)) {
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
} else if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
Gdx.app.exit();
}
}
@Override
public void show() {
atlas = new TextureAtlas("ui/Button.pack");
skin = new Skin(atlas);
stage = new Stage();
table = new Table(skin);
black = new BitmapFont(Gdx.files.internal("fonts/Black.fnt"), false);
black.setScale(Gdx.graphics.getWidth() / 1280f,
Gdx.graphics.getHeight() / 720f);
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
buttonStyle = new TextButtonStyle();
buttonStyle.up = skin.getDrawable("ButtonUp9");
buttonStyle.down = skin.getDrawable("ButtonDown9");
buttonStyle.pressedOffsetX = 1;
buttonStyle.pressedOffsetY = -1;
buttonStyle.font = black;
scene = new TextButton[3];
scene[0] = new TextButton("Scenario 1", buttonStyle);
scene[1] = new TextButton("Scenario 2", buttonStyle);
scene[2] = new TextButton("Scenario 3", buttonStyle);
scene[0].addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener())
.setScreen(new Intro1());
Gdx.audio.newSound(Gdx.files.internal("sounds/button.mp3"))
.play(1);
Gdx.input.vibrate(50);
dispose();
}
});
scene[1].addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener())
.setScreen(new Intro2());
Gdx.audio.newSound(Gdx.files.internal("sounds/button.mp3"))
.play(1);
Gdx.input.vibrate(50);
dispose();
}
});
scene[2].addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener())
.setScreen(new Intro3());
Gdx.audio.newSound(Gdx.files.internal("sounds/button.mp3"))
.play(1);
Gdx.input.vibrate(50);
dispose();
}
});
scene[0].pad(10);
scene[1].pad(10f);
scene[2].pad(10f);
table.add(scene[0]);
table.add(scene[1]);
table.getCell(scene[1]).space(20f);
table.add(scene[2]);
stage.addActor(table);
}
@Override
public void dispose() {
stage.dispose();
skin.dispose();
atlas.dispose();
black.dispose();
}
}
您忘记处理声音/音乐对象。您可以在游戏类的处置方法中执行此操作。