0

What i'am doing is showing a tiledmap on the full screen , and it works fine.

The character moves perfectly and the camera too.

What i want is :

Showing some text or imageButton over the map like a menu button on the left of the screen.

I tried to use a stage from scene2d library and i was able to draw what i want over the screen , the problem is that my player Sprite is hideen.

My code look as follows:

public class MapScreen implements Screen {

    private TiledMap initialMap;
    private static OrthogonalTiledMapRenderer orthogonalTiledMapRenderer;
    private OrthographicCamera camera;
    //player with x and y coordinates
    private Player player;


        public MapScreen() {
        //my player
        player = new player();
        //the map
        initialMap = getinitialMap();
        //i ask the orthogonalTiledMapRenderer to render my map
        orthogonalTiledMapRenderer = new OrthogonalTiledMapRenderer(currentmap);
        //I create the camera and i make the player in the middle of the screen
        camera = new OrthographicCamera();
        camera.position.set(w / 2, h / 2, 0);
        camera.translate(player.getPosition().x * 32, player.getPosition().y * 32);
        camera.translate(-16 * 32, -8 * 32);
        camera.update();
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        camera.update();
        orthogonalTiledMapRenderer.getSpriteBatch().begin();
        orthogonalTiledMapRenderer.setView(camera);
        MapLayers mapLayers = initialMap.getLayers();
        //I render all the layer with the orthogonalTiledMapRenderer 
        for (int i = 0; i < mapLayers.getCount(); i++) {
            orthogonalTiledMapRenderer
                    .renderTileLayer((TiledMapTileLayer) mapLayers.get(i));
        }
        //handling event
        handleEvent();
        //i update the player position
        player.move();
        //renderig the player sprite
        player.render(orthogonalTiledMapRenderer.getSpriteBatch());
       orthogonalTiledMapRenderer.getSpriteBatch().end();

    }



}

**my player Sprite becomes invisible **

user3521250
  • 115
  • 3
  • 14

1 Answers1

1

Try to move

stage.draw();

before you begin sprite batch.

Or maybe after, but then your player will have less z-index then stage elements.

Aleksandrs
  • 1,488
  • 1
  • 14
  • 34