我正在做的是在全屏幕上显示平铺地图,它运行正常。
角色也完美地移动了镜头。
我想要的是:
在地图上显示一些text或imageButton,就像屏幕左侧的菜单按钮一样。
我尝试使用scene2d库中的一个舞台,我能够在屏幕上绘制我想要的内容,问题是我的播放器Sprite是隐藏的。
我的代码如下:
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();
}
}
**我的玩家精灵变得不可见**
答案 0 :(得分:1)
尝试移动
stage.draw();
开始精灵批处理之前。
或者也许之后,但是你的玩家将拥有更少的z-index然后是舞台元素。