libGDX TileMapRenderer not doing anything
I was using this tutorial and tried to make the TileMapRenderer work, but I can't. It never renders anything, no matter what i do.
src:
public class GameScreen implements Screen {
TestGame game;
TiledMap map;
TileAtlas atlas;
TileMapRenderer tmr;
OrthographicCamera cam;
public GameScreen(TestGame game){
this.game = game;
map = TiledLoader.createMap(Gdx.files.internal("maps/level1.tmx"));
atlas = new TileAtlas(map, Gdx.files.internal("maps/"));
tmr = new TileMapRenderer(map, atlas, 5, 5);
cam = new OrthographicCamera(800,600);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isKeyPressed(Keys.LEFT)){
cam.position.x=cam.position.x-Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.RIGHT)){
cam.position.x=cam.position.x+Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.DOWN)){
cam.position.y=cam.position.y-Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.UP)){
cam.position.y=cam.position.y+Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.PLUS)){
cam.zoom-=Gdx.graphics.getDeltaTime();
}
if(Gdx.input.isKeyPressed(Keys.MINUS)){
cam.zoom+=Gdx.graphics.getDeltaTime();
}
cam.update();
// render map
tmr.render(cam);
System.out.println("rendering");
}
I was using this tutorial and tried to make the TileMapRenderer work, but I can't. It never renders anything, no matter what i do.
src:
public class GameScreen implements Screen {
TestGame game;
TiledMap map;
TileAtlas atlas;
TileMapRenderer tmr;
OrthographicCamera cam;
public GameScreen(TestGame game){
this.game = game;
map = TiledLoader.createMap(Gdx.files.internal("maps/level1.tmx"));
atlas = new TileAtlas(map, Gdx.files.internal("maps/"));
tmr = new TileMapRenderer(map, atlas, 5, 5);
cam = new OrthographicCamera(800,600);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isKeyPressed(Keys.LEFT)){
cam.position.x=cam.position.x-Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.RIGHT)){
cam.position.x=cam.position.x+Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.DOWN)){
cam.position.y=cam.position.y-Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.UP)){
cam.position.y=cam.position.y+Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.PLUS)){
cam.zoom-=Gdx.graphics.getDeltaTime();
}
if(Gdx.input.isKeyPressed(Keys.MINUS)){
cam.zoom+=Gdx.graphics.getDeltaTime();
}
cam.update();
// render map
tmr.render(cam);
System.out.println("rendering");
}
No comments:
Post a Comment