Search in sources :

Example 1 with TmxMapLoader

use of com.badlogic.gdx.maps.tiled.TmxMapLoader in project libgdx by libgdx.

the class TiledMapLayerOffsetTest 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.zoom = 2;
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    shapeRenderer = new ShapeRenderer();
    assetManager = new AssetManager();
    assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
    assetManager.load(MAP_ORTHO, TiledMap.class);
    assetManager.load(MAP_ISO, TiledMap.class);
    assetManager.load(MAP_ISO_STAG, TiledMap.class);
    assetManager.load(MAP_HEX_X, TiledMap.class);
    assetManager.load(MAP_HEX_Y, TiledMap.class);
    assetManager.finishLoading();
    map = assetManager.get(MAP_ORTHO);
    renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
Also used : OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) AssetManager(com.badlogic.gdx.assets.AssetManager) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 2 with TmxMapLoader

use of com.badlogic.gdx.maps.tiled.TmxMapLoader 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();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) Animation(com.badlogic.gdx.graphics.g2d.Animation) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 3 with TmxMapLoader

use of com.badlogic.gdx.maps.tiled.TmxMapLoader in project high-flyer by sangngh.

the class AbstractLevel method init.

protected void init() {
    camera = new OrthographicCamera();
    camera.setToOrtho(false, game.getSettings().getWindowWidth(), game.getSettings().getWindowHeight());
    camera.update();
    final String tiledMapPath = "data/screens/" + getLevelMap();
    assetManager = new AssetManager();
    assetManager.setLoader(TiledMap.class, new TmxMapLoader(new ClasspathFileHandleResolver()));
    assetManager.load(tiledMapPath, TiledMap.class);
    assetManager.load(SPRITES, Texture.class);
    assetManager.finishLoading();
    TiledMap map = assetManager.get(tiledMapPath);
    renderer = new OrthogonalTiledMapRenderer(map);
    player = new Player(this.game, getSpriteTextures(), map.getLayers(), 480, 1045);
    player.setPosition(0 * TILE_SIZE, 6 * TILE_SIZE);
    player.rotate(90);
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/Amatic-Bold.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 40;
    // parameter.characters = "Score: "+game.getState().getScore();
    bitMapFontName = generator.generateFont(parameter);
    generator.dispose();
}
Also used : OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) Player(com.relic.highflyer.sprites.Player) AssetManager(com.badlogic.gdx.assets.AssetManager) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) ClasspathFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.ClasspathFileHandleResolver) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap)

Example 4 with TmxMapLoader

use of com.badlogic.gdx.maps.tiled.TmxMapLoader in project var3dframe by Var3D.

the class VGame method getTiledMap.

/**
 * tieldMap
 */
public TiledMap getTiledMap(String name) {
    if (assets.isLoaded(name, TiledMap.class)) {
        return assets.get(name, TiledMap.class);
    } else {
        assets.setLoader(TiledMap.class, new TmxMapLoader());
        assets.load(name, TiledMap.class);
        assets.finishLoading();
        return assets.get(name, TiledMap.class);
    }
}
Also used : TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader)

Example 5 with TmxMapLoader

use of com.badlogic.gdx.maps.tiled.TmxMapLoader in project libgdx by libgdx.

the class TiledMapAssetManagerTest 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.zoom = 2;
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    assetManager = new AssetManager();
    assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
    assetManager.load("data/maps/tiled/isometric_grass_and_water.tmx", TiledMap.class);
    assetManager.finishLoading();
    map = assetManager.get("data/maps/tiled/isometric_grass_and_water.tmx");
    renderer = new IsometricTiledMapRenderer(map, 1f / 64f);
    String mapCustomValue = map.getProperties().get(MAP_PROPERTY_NAME, String.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + MAP_PROPERTY_NAME + ", Value : " + mapCustomValue);
    if (!MAP_PROPERTY_VALUE.equals(mapCustomValue)) {
        throw new RuntimeException("Failed to get map properties");
    }
    boolean boolCustomValue = map.getProperties().get(BOOL_PROPERTY_NAME, Boolean.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + BOOL_PROPERTY_NAME + ", Value : " + boolCustomValue);
    if (boolCustomValue != BOOL_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get boolean map properties");
    }
    int intCustomValue = map.getProperties().get(INT_PROPERTY_NAME, Integer.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + INT_PROPERTY_NAME + ", Value : " + intCustomValue);
    if (intCustomValue != INT_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get int map properties");
    }
    float floatCustomValue = map.getProperties().get(FLOAT_PROPERTY_NAME, Float.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + FLOAT_PROPERTY_NAME + ", Value : " + floatCustomValue);
    if (floatCustomValue != FLOAT_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get float map properties");
    }
    TiledMapTileSet tileset = map.getTileSets().getTileSet(0);
    String tilesetCustomValue = tileset.getProperties().get(TILESET_PROPERTY_NAME, String.class);
    if (!TILESET_PROPERTY_VALUE.equals(tilesetCustomValue)) {
        throw new RuntimeException("Failed to get tileset properties");
    }
    TiledMapTile tile = tileset.getTile(1);
    String tileCustomValue = tile.getProperties().get(TILE_PROPERTY_NAME, String.class);
    if (!TILE_PROPERTY_VALUE.equals(tileCustomValue)) {
        throw new RuntimeException("Failed to get tile properties");
    }
    MapLayer layer = map.getLayers().get(0);
    String layerCustomValue = layer.getProperties().get(LAYER_PROPERTY_NAME, String.class);
    if (!LAYER_PROPERTY_VALUE.equals(layerCustomValue)) {
        throw new RuntimeException("Failed to get layer properties");
    }
}
Also used : TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) AssetManager(com.badlogic.gdx.assets.AssetManager) TiledMapTileSet(com.badlogic.gdx.maps.tiled.TiledMapTileSet) MapLayer(com.badlogic.gdx.maps.MapLayer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) IsometricTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Aggregations

TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)10 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)6 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)5 AssetManager (com.badlogic.gdx.assets.AssetManager)4 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)4 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)3 MapLayer (com.badlogic.gdx.maps.MapLayer)3 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)3 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)2 FileHandle (com.badlogic.gdx.files.FileHandle)2 Texture (com.badlogic.gdx.graphics.Texture)2 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 IsometricTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer)2 ClasspathFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.ClasspathFileHandleResolver)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 Animation (com.badlogic.gdx.graphics.g2d.Animation)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1