3
\$\begingroup\$

I am making a 2D tile based game in LibGDX. I am using Scene2D Stage in my Screens. I am also using GLES2.0 in my game. When I changed from GL10 to GL20. On pressing the back button, my game is displaying only the blue screen (i.e. set as gl background)but it is ot displaying my sprite. I have used this class as my Base Screen

public abstract class AbstractScreen implements Screen {
// Game reference
private Game game;

// Initial
private String screenName = "Untitled Screen";
private final Stage stage;

// Screen second counter (1 second tick)
private float startTime = System.nanoTime();
public static float SECONDS_TIME = 0;

// Animation timer (If any animation is used)
private float stateTime = 0;

// Custom back button
private boolean isBackButtonActive = false;


public AbstractScreen(Game game, String screenName) {
    super();
    this.game = game;
    if (screenName.equals("")) {
        this.screenName = "Untitled Screen";
    } else {
        this.screenName = screenName;
    }

    //
    stage = new Stage(AppSettings.SCREEN_W, AppSettings.SCREEN_H, false);
    stage.getCamera().position.set(AppSettings.SCREEN_W / 2,
            AppSettings.SCREEN_H / 2, 0);

    // Receive inputs from stage
    Gdx.input.setInputProcessor(stage);
}

@Override
public void render(float delta) {
    // Update screen clock (1 second tick)
    // ############################################################
    if (System.nanoTime() - startTime >= 1000000000) {
        SECONDS_TIME++;
        startTime = System.nanoTime();
    }

    // Update animation times
    // ############################################################
    stateTime += delta;

    // Snippet (Clear screen and give red color)
    // ############################################################

//      Gdx.gl.glClearColor(0, 1, 0.3f, 1);
//      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    //Changed to GLES2.0
    Gdx.gl20.glClearColor(0, 1, 0.3f, 1);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // Update stage/actors logic (update() method in previous games)
    // ############################################################
    stage.act(delta);

    // Render drawings (draw()/render() methods in previous games)
    // ############################################################
    stage.draw();

    // Custom back button
    // ############################################################
    if (isBackButtonActive) {
        if (Gdx.input.isKeyPressed(Keys.BACK)) {
            keyBackPressed();
        }
    }
}

/**
 * Set stage background. Sets the image (Adds to stage as image)
 * 
 * @param backgroundTextureRegion
 * 
 * */
public void setBackgroundTexture(TextureRegion textureBackground) {
    Drawable tBg = new TextureRegionDrawable(textureBackground);
    Image imgbg = new Image(tBg, Scaling.stretch);
    imgbg.setFillParent(true);
    stage.addActor(imgbg);
    //
    MtxLogger.log(logActive, true, logTag, "SCREEN BG IMAGE SET: "
            + getScreenName());
}


public void setBackButtonActive(boolean isBackButtonActive) {
    Gdx.input.setCatchBackKey(true);
    this.isBackButtonActive = isBackButtonActive;
    //
    MtxLogger.log(logActive, true, logTag, "SCREEN BACK BUTTON SET: "
            + getScreenName());
}

public void keyBackPressed() {
}

public Game getGame() {
    return game;
}


public void setGame(Game game) {
    this.game = game;
}

public String getScreenName() {
    return screenName;
}

/**
 * Set screen name
 * */
public void setScreenName(String screenName) {
    this.screenName = screenName;
}

/**
 * Get screen name
 * */

public boolean isBackButtonActive() {
    return isBackButtonActive;
}

public Stage getStage() {
    return stage;
}

@Override
public void show() {
    MtxLogger.log(logActive, true, logTag, "SCREEN SHOW: "
            + getScreenName());
}

@Override
public void hide() {
    MtxLogger.log(logActive, true, logTag, "SCREEN HIDE: "
            + getScreenName());
}

@Override
public void pause() {
    MtxLogger.log(logActive, true, logTag, "SCREEN PAUSE: "
            + getScreenName());
}

@Override
public void resume() {
    MtxLogger.log(logActive, true, logTag, "SCREEN RESUME: "
            + getScreenName());
}

@Override
public void dispose() {
    stage.dispose();

    // Add items here for log
    String strDisposedItems = "Stage, ";
    MtxLogger.log(logActive, true, logTag, "$$ :: SCREEN DISPOSING: "
            + getScreenName() + " DISPOSED: " + strDisposedItems);
}

}

I tried a lot of things but they didn't work. I think it may be some GLES issue or I am not disposing something onKeyBackPressed(). I am using

renderer = new OrthogonalTiledMapRenderer(world.map, 1/16f);
batch = renderer.getSpriteBatch();

in my WorldRenderer class to draw the Tiled Map and other sprites. For drawing the UI/ Game Buttons I am using Scene2D Buttons using getStage().getSpriteBatch();

\$\endgroup\$
  • \$\begingroup\$ This question appears to be off-topic because it is about debugging code. Although it is more specific than most debug questions, it still requires more narrowing-down by the poster. There would seem to be relevant code that is not posted (pastebin that, please). \$\endgroup\$ – Seth Battin Dec 19 '13 at 4:46
  • \$\begingroup\$ Have you set to cfg.useGL20 = true; \$\endgroup\$ – daniel Dec 20 '13 at 17:44
  • \$\begingroup\$ Please, explain better what you want to achieve and what you're getting instead. \$\endgroup\$ – Gustavo Maciel Jan 2 '14 at 21:19

Browse other questions tagged or ask your own question.