我希望splash2在得分为2时显示屏幕。现在第一个启动仍然显示,我不知道如何在得分时用splash2替换它。
public class Click1 implements Screen {
private SpriteBatch batch;
private Sprite splash;
private Sprite splash2;
private Sprite splash3;
private Sprite splash4;
private Sprite splash5;
private Viewport viewport;
private Camera camera;
private Clickhud1 hud;
private float dt;
private static Integer score;
public Click1() {
}
public void update(float dt){
handleInput(dt);
hud.update(dt);
}
@Override
public void show() {
camera = new PerspectiveCamera();
viewport = new FitViewport(800, 480, camera);
batch = new SpriteBatch();
splash = new Sprite(new Texture("Clicks.png"));
splash2 = new Sprite(new Texture("Clicks2.png"));
splash3 = new Sprite(new Texture("Clicks3.png"));
splash4 = new Sprite(new Texture("Clicks4.png"));
splash5 = new Sprite(new Texture("Clicks5.png"));
hud = new Clickhud1(Globals.game.batch);
}
@Override
public void render(float delta) {
update(delta);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if(score <= 1) {
batch.begin();
batch.setColor(splash.getColor());
batch.draw(
splash,
Gdx.graphics.getWidth() / 2f - splash.getRegionWidth() / 2f,
Gdx.graphics.getHeight() / 2f - splash.getRegionHeight() / 2f,
splash.getRegionWidth(),
splash.getRegionHeight());
batch.end();
}
if(score <= 2) {
batch.begin();
batch.setColor(splash2.getColor());
batch.draw(
splash2,
Gdx.graphics.getWidth() / 2f - splash2.getRegionWidth() / 2f,
Gdx.graphics.getHeight() / 2f - splash2.getRegionHeight() / 2f,
splash2.getRegionWidth(),
splash2.getRegionHeight());
batch.end();
}
if(score == 3) {
batch.begin();
batch.setColor(splash3.getColor());
batch.draw(
splash3,
Gdx.graphics.getWidth() / 2f - splash3.getRegionWidth() / 2f,
Gdx.graphics.getHeight() / 2f - splash3.getRegionHeight() / 2f,
splash3.getRegionWidth(),
splash3.getRegionHeight());
batch.end();
}
if(score == 4) {
batch.begin();
batch.setColor(splash4.getColor());
batch.draw(
splash4,
Gdx.graphics.getWidth() / 2f - splash4.getRegionWidth() / 2f,
Gdx.graphics.getHeight() / 2f - splash4.getRegionHeight() / 2f,
splash4.getRegionWidth(),
splash4.getRegionHeight()
);
batch.end();
}
if(score >= 5) {
batch.begin();
batch.setColor(splash5.getColor());
batch.draw(
splash5,
Gdx.graphics.getWidth() / 2f - splash5.getRegionWidth() / 2f,
Gdx.graphics.getHeight() / 2f - splash5.getRegionHeight() / 2f,
splash5.getRegionWidth(),
splash5.getRegionHeight()
);
batch.end();
}
Globals.game.batch.setProjectionMatrix(hud.stage.getCamera().combined);
hud.stage.draw();
}
@Override
public void resize(int width, int height) {
batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
viewport.update(width, height);
}
@Override
public void hide() {
dispose();
}
@Override
public void dispose() {
batch.dispose();
splash.getTexture().dispose();
splash2.getTexture().dispose();
splash3.getTexture().dispose();
splash4.getTexture().dispose();
splash5.getTexture().dispose();
hud.dispose();
}
}
好的,这就是整个班级。 我无法理解为什么Sprite在得分时不会改变。