Reputation: 353
I have problems with TiledMapRenderer
. I have made a tmx map with 4 tile objects and 1 tile 64x64 each tile in the map with Tiled Map Editor
. But I can't figure out what I have missed. There is nothing on the screen. The map and tile set are in assets folder. I have google a lot, copy pasted code from tutorials and GDX
TiledMap
test but see nothing on my Alcatel One Touch Pixi 4007d
GLES 2.0
ready phone except fps counter and camera position. What have I missed? May be the answers will be helpful for other novice libGDX
programmers.
I have checked the map in the debugger and all the variables were initialized, there also were a layer in the map.
Here is the code of the Game
class
public class GameMain extends Game implements InputProcessor
{
private TiledMap map;
private TiledMapRenderer renderer;
private OrthographicCamera camera;
private BitmapFont font;
private SpriteBatch batch;
Vector2 mPrevTouch;
@Override
public void create () {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, (w / h) * 10, 10);
camera.update();
Gdx.input.setInputProcessor(this);
font = new BitmapFont();
batch = new SpriteBatch();
map = new TmxMapLoader().load("test.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
}
@Override
public void render () {
Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
renderer.setView(camera);
renderer.render();
batch.begin();
font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
font.draw(batch, "Pos: " + camera.position.x + " " + camera.position.y, 20, 20);
batch.end();
}
@Override
public void dispose () {
map.dispose();
}
@Override
public boolean keyDown(int arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyUp(int arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean mouseMoved(int arg0, int arg1) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean scrolled(int arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int arg2) {
if (mPrevTouch == null)
mPrevTouch = new Vector2(0, 0);
else
camera.translate(new Vector2(screenX - mPrevTouch.x, screenY - mPrevTouch.y));
mPrevTouch.x = screenX;
mPrevTouch.y = screenY;
return true;
}
@Override
public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
return false;
}
}
Upvotes: 0
Views: 452
Reputation: 2155
Your code looks OK, so I think you have problem with camera size or camera position. What is the size of your TMX map? + try to create camera this way:
tiledMapCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Upvotes: 1