LibGdx drawing weird behaviour

Posted by Ryckes on Game Development See other posts from Game Development or by Ryckes
Published on 2012-09-02T18:17:13Z Indexed on 2012/09/02 21:49 UTC
Read the original article Hit count: 318

Filed under:
|
|

I am finding strange behaviour while rendering TextureRegions in my game, only when pausing it. I am making a game for Android, in Java with LibGdx.

When I comment out the line "drawLevelPaused()" everything seems to work fine, both running and paused. When it's not commented, everything works fine until I pause the screen, then it draws those two rectangles, but maybe ships are not shown, and if I comment out drawShips() and drawTarget() (just trying) maybe one of the planets disappears, or if I change the order, other things disappear and those that disappeared before now are rendered again. I can't find the way to fix this behaviour

I beg your help, and I hope it's my mistake and not a LibGdx issue. I use OpenGL ES 2.0, stated in AndroidManifest.xml, if it is of any help. Thank you in advance.

My Screen render method(game loop) is as follows:

@Override
public void render(float delta)
{
    Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);


    controller.update(delta);
    renderer.render();
}

When world state is PAUSED controller.update does nothing at all, there is a switch in it. And renderer.render() is as follows:

public void render()
{
    int worldState=this.world.getWorldState();

    updateCamera();
    spriteBatch.begin();
    drawPlanets();
    drawTarget();
    drawShips();

    if(worldState==World.PAUSED)
    {
        drawLevelPaused();
    }
    else if(worldState==World.LEVEL_WON)
    {
        drawLevelWin();
    }
    spriteBatch.end();
}

And those methods are:

private void updateCamera()
{
    this.offset=world.getCameraOffset();
}

private void drawPlanets()
{
    for(Planet planet : this.world.getPlanets())
    {
        this.spriteBatch.draw(this.textures.getTexture(planet.getTexture()), (planet.getPosition().x - this.offset[0]) * ppuX, (planet.getPosition().y - this.offset[1]) * ppuY);
    }
}

private void drawTarget()
{
    Target target=this.world.getTarget();
    this.spriteBatch.draw(this.textures.getTexture(target.getTexture()), (target.getPosition().x - this.offset[0]) * ppuX, (target.getPosition().y - this.offset[1]) * ppuY);
}

private void drawShips()
{
    for(Ship ship : this.world.getShips())
    {
        this.spriteBatch.draw(this.textures.getTexture(ship.getTexture()), (ship.getPosition().x - this.offset[0]) * ppuX, (ship.getPosition().y - this.offset[1]) * ppuY, ship.getBounds().width*ppuX/2, ship.getBounds().height*ppuY/2, ship.getBounds().width*ppuX, ship.getBounds().height*ppuY, 1.0f, 1.0f, ship.getAngle()-90.0f);
    }

    if(this.world.getStillShipVisibility())
    {
        Ship ship=this.world.getStillShip();
        Arrow arrow=this.world.getArrow();
        this.spriteBatch.draw(this.textures.getTexture(ship.getTexture()), (ship.getPosition().x - this.offset[0]) * ppuX, (ship.getPosition().y - this.offset[1]) * ppuY, ship.getBounds().width*ppuX/2, ship.getBounds().height*ppuY/2, ship.getBounds().width*ppuX, ship.getBounds().height*ppuY, 1f, 1f, ship.getAngle() - 90f);
        this.spriteBatch.draw(this.textures.getTexture(arrow.getTexture()), (ship.getCenter().x - this.offset[0] - arrow.getBounds().width/2) * ppuX, (ship.getCenter().y - this.offset[1]) * ppuY, arrow.getBounds().width*ppuX/2, 0, arrow.getBounds().width*ppuX, arrow.getBounds().height*ppuY, 1f, arrow.getRate(), ship.getAngle() - 90f);

    }
}

private void drawLevelPaused()
{
    this.shapeRenderer.begin(ShapeType.FilledRectangle);
    this.shapeRenderer.setColor(0f, 0f, 0f, 0.8f);

    this.shapeRenderer.filledRect(0, 0, this.width/this.ppuX, PAUSE_MARGIN_HEIGHT/this.ppuY);
    this.shapeRenderer.filledRect(0, (this.height-PAUSE_MARGIN_HEIGHT)/this.ppuY, this.width/this.ppuX, PAUSE_MARGIN_HEIGHT/this.ppuY);

    this.shapeRenderer.end();

    for(Button button : this.world.getPauseButtons())
    {
        this.spriteBatch.draw(this.textures.getTexture(button.getTexture()), (button.getPosition().x - this.offset[0]) * this.ppuX, (button.getPosition().y - this.offset[1]) * this.ppuY);
    }

}

© Game Development or respective owner

Related posts about java

Related posts about android