I’ve got the camera working and showing my map, but everything looks zoomed in. I’ve gone through the wiki and can’t seem to find how to keep the tiles at 16x16 instead of stretching or zooming them…I can zoom in and out, but that doesn’t solve the stretching problem…
package com.bassex.oasishm;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.tiled.*;
public class OasisGame implements ApplicationListener {
private OrthographicCamera camera;
private SpriteBatch batch;
private Texture texture;
private Sprite sprite;
TileMapRenderer mapRenderer;
TileAtlas atlas;
TiledMap map;
static final int WIDTH = 800;
static final int HEIGHT = 600;
@Override
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera(HEIGHT,WIDTH);
batch = new SpriteBatch();
//Map Stuff
map = TiledLoader.createMap(Gdx.files.internal("data/testlvl.tmx"));
atlas = new TileAtlas(map, Gdx.files.internal("data"));
mapRenderer = new TileMapRenderer(map, atlas, 8, 8);
//camera.position.x = WIDTH / 2;
//camera.position.y = HEIGHT / 2;
camera.setToOrtho(false, WIDTH / 2,HEIGHT / 2);
}
@Override
public void dispose() {
batch.dispose();
texture.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isKeyPressed(Keys.LEFT)){
camera.position.x=camera.position.x-Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.RIGHT)){
camera.position.x=camera.position.x+Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.DOWN)){
camera.position.y=camera.position.y-Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.UP)){
camera.position.y=camera.position.y+Gdx.graphics.getDeltaTime()*300;
}
if(Gdx.input.isKeyPressed(Keys.PLUS)){
camera.zoom-=Gdx.graphics.getDeltaTime();
}
if(Gdx.input.isKeyPressed(Keys.MINUS)){
camera.zoom+=Gdx.graphics.getDeltaTime();
}
camera.update();
mapRenderer.render(camera);
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
I’m trying to find a good TiledMap tutorial but haven’t had much luck as it seems TiledMap has been changed…so I don’t know what is correct and incorrect on the tutorials I can find…I’m not even sure HOW to begin drawing my character into the map or anything…Does anyone have any good tutorials for this or any good information? It would be greatly appreciated.