use of com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer in project libgdx by libgdx.
the class SuperKoalio method create.
@Override
public void create() {
// load the koala frames, split them, and assign them to Animations
koalaTexture = new Texture("data/maps/tiled/super-koalio/koalio.png");
TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0];
stand = new Animation(0, regions[0]);
jump = new Animation(0, regions[1]);
walk = new Animation(0.15f, regions[2], regions[3], regions[4]);
walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);
// figure out the width and height of the koala for collision
// detection and rendering by converting a koala frames pixel
// size into world units (1 unit == 16 pixels)
Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth();
Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight();
// load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);
// create an orthographic camera, shows us 30x20 units of the world
camera = new OrthographicCamera();
camera.setToOrtho(false, 30, 20);
camera.update();
// create the Koala we want to move around the world
koala = new Koala();
koala.position.set(20, 20);
debugRenderer = new ShapeRenderer();
}
use of com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer in project libgdx by libgdx.
the class TiledMapAtlasDirectLoaderTest method create.
@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();
cameraController = new OrthoCamController(camera);
Gdx.input.setInputProcessor(cameraController);
font = new BitmapFont();
batch = new SpriteBatch();
map = new AtlasTmxMapLoader().load("data/maps/tiled-atlas-processed/test.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
use of com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer in project libgdx by libgdx.
the class TiledMapDirectLoaderTest method create.
@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();
cameraController = new OrthoCamController(camera);
Gdx.input.setInputProcessor(cameraController);
font = new BitmapFont();
batch = new SpriteBatch();
map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
use of com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer in project libgdx by libgdx.
the class TiledMapLayerOffsetTest method render.
@Override
public void render() {
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) {
if (mapType != 0) {
if (renderer instanceof Disposable)
((Disposable) renderer).dispose();
mapType = 0;
map = assetManager.get(MAP_ORTHO);
renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
} else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) {
if (mapType != 1) {
if (renderer instanceof Disposable)
((Disposable) renderer).dispose();
mapType = 1;
map = assetManager.get(MAP_ORTHO);
renderer = new OrthoCachedTiledMapRenderer(map, 1f / 32f);
((OrthoCachedTiledMapRenderer) renderer).setBlending(true);
}
} else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) {
if (mapType != 2) {
if (renderer instanceof Disposable)
((Disposable) renderer).dispose();
mapType = 2;
map = assetManager.get(MAP_ISO);
renderer = new IsometricTiledMapRenderer(map, 1f / 48f);
}
} else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_4)) {
if (mapType != 3) {
if (renderer instanceof Disposable)
((Disposable) renderer).dispose();
mapType = 3;
map = assetManager.get(MAP_ISO_STAG);
renderer = new IsometricStaggeredTiledMapRenderer(map, 1f / 48f);
}
} else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_5)) {
if (mapType != 4) {
if (renderer instanceof Disposable)
((Disposable) renderer).dispose();
mapType = 4;
map = assetManager.get(MAP_HEX_X);
renderer = new HexagonalTiledMapRenderer(map, 1f / 48f);
}
} else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_6)) {
if (mapType != 5) {
if (renderer instanceof Disposable)
((Disposable) renderer).dispose();
mapType = 5;
map = assetManager.get(MAP_HEX_Y);
renderer = new HexagonalTiledMapRenderer(map, 1f / 48f);
}
}
Gdx.gl.glClearColor(100f / 255f, 100f / 255f, 250f / 255f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
// add margin to view bounds so it is easy to see any issues with clipping, calculated same way as
// BatchTiledMapRenderer#setView (OrthographicCamera)
final float margin = 3;
final float width = camera.viewportWidth * camera.zoom - margin * 2;
final float height = camera.viewportHeight * camera.zoom - margin * 2;
final float w = width * Math.abs(camera.up.y) + height * Math.abs(camera.up.x);
final float h = height * Math.abs(camera.up.y) + width * Math.abs(camera.up.x);
final float x = camera.position.x - w / 2;
final float y = camera.position.y - h / 2;
renderer.setView(camera.combined, x, y, w, h);
renderer.render();
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeType.Line);
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(x, y, w, h);
shapeRenderer.end();
batch.begin();
font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
font.draw(batch, "Switch type with 1-6", Gdx.graphics.getHeight() - 100, 50);
font.draw(batch, renderer.getClass().getSimpleName(), Gdx.graphics.getHeight() - 100, 20);
batch.end();
}
use of com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer in project libgdx by libgdx.
the class TiledMapPackerTestRender method create.
@Override
public void create() {
atlasTmxMapLoader = new AtlasTmxMapLoader(new InternalFileHandleResolver());
params = new AtlasTmxMapLoader.AtlasTiledMapLoaderParameters();
params.generateMipMaps = false;
params.convertObjectToTileSpace = false;
params.flipY = true;
viewport = new FitViewport(WORLD_WIDTH, WORLD_HEIGHT);
cam = (OrthographicCamera) viewport.getCamera();
map = atlasTmxMapLoader.load(TMX_LOC, params);
mapRenderer = new OrthogonalTiledMapRenderer(map, UNIT_SCALE);
}
Aggregations