I am having a hard time getting a map to display correctly on my android app using LibGdx. First up here is my code:
public class PlayState extends State {
private LittleMan littleMan;
private TiledMap map;
OrthogonalTiledMapRenderer tiledMapRenderer;
OrthographicCamera camera;
public PlayState(GameStateManager gsm) {
super(gsm);
littleMan = new LittleMan(50,100);
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, w,h);
camera.update();
TmxMapLoader loader = new TmxMapLoader();
map = loader.load("ste_barbe_map.tmx");
tiledMapRenderer = new OrthogonalTiledMapRenderer(map);
}
@Override
protected void handleInput() {
}
@Override
public void update(float dt) {
}
@Override
public void render(SpriteBatch sb) {
// if viewport modified
// sb.setProjectionMatrix(cam.combined);
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
/*
sb.begin();
sb.draw(littleMan.getTexture(),littleMan.getPosition().x,littleMan.getPosition().y);
sb.end();
*/
}
@Override
// free some ressources
public void dispose() {
}
}
So when i try to run the app and call the render method i just get a red background with nothing on it.
Here are some things i tried:
- using a smaller map with just a line of tiles, this displays correctly (even though i'm not sure its at the right position):
- playing around with scaling: i can display the map but its either very small or i can only see the edges
with this line changed to : tiledMapRenderer = new OrthogonalTiledMapRenderer(map,0.5f);
I get:
And with this line : tiledMapRenderer = new OrthogonalTiledMapRenderer(map,1/8f);
I get this very zoomed out image of the map:
Does anyone know what i am doing wrong? Maybe my tmx file is bad, maybe it's something with the camera, or something else i really don't know.
Thanks for the help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…