Search in sources :

Example 6 with OrthoCamController

use of com.badlogic.gdx.tests.utils.OrthoCamController in project libgdx by libgdx.

the class TideMapDirectLoaderTest 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 TideMapLoader().load("data/maps/tide/Map01.tide");
    renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
Also used : OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TideMapLoader(com.badlogic.gdx.maps.tiled.TideMapLoader) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 7 with OrthoCamController

use of com.badlogic.gdx.tests.utils.OrthoCamController in project libgdx by libgdx.

the class HexagonalTiledMapTest method create.

@Override
public void create() {
    super.create();
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 480, 480);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    hexture = new Texture(Gdx.files.internal("data/maps/tiled/hex/hexes.png"));
    TextureRegion[][] hexes = TextureRegion.split(hexture, 112, 97);
    map = new TiledMap();
    MapLayers layers = map.getLayers();
    TiledMapTile[] tiles = new TiledMapTile[3];
    tiles[0] = new StaticTiledMapTile(new TextureRegion(hexes[0][0]));
    tiles[1] = new StaticTiledMapTile(new TextureRegion(hexes[0][1]));
    tiles[2] = new StaticTiledMapTile(new TextureRegion(hexes[1][0]));
    for (int l = 0; l < 1; l++) {
        TiledMapTileLayer layer = new TiledMapTileLayer(45, 30, 112, 97);
        for (int y = 0; y < 30; y++) {
            for (int x = 0; x < 45; x++) {
                int id = (int) (Math.random() * 3);
                Cell cell = new Cell();
                cell.setTile(tiles[id]);
                layer.setCell(x, y, cell);
            }
        }
        layers.add(layer);
    }
    renderer = new HexagonalTiledMapRenderer(map);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) HexagonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapLayers(com.badlogic.gdx.maps.MapLayers)

Example 8 with OrthoCamController

use of com.badlogic.gdx.tests.utils.OrthoCamController in project libgdx by libgdx.

the class IsometricTileTest method create.

@Override
public void create() {
    cam = new OrthographicCamera(480, 320);
    camController = new OrthoCamController(cam);
    Gdx.input.setInputProcessor(camController);
    renderer = new ShapeRenderer();
    texture = new Texture(Gdx.files.internal("data/isotile.png"));
    Random rand = new Random();
    for (int i = 0; i < LAYERS; i++) {
        caches[i] = new SpriteCache();
        SpriteCache cache = caches[i];
        cache.beginCache();
        int colX = HEIGHT * TILE_WIDTH / 2 - TILE_WIDTH / 2;
        int colY = BOUND_Y - TILE_HEIGHT_DIAMOND;
        for (int x = 0; x < WIDTH; x++) {
            for (int y = 0; y < HEIGHT; y++) {
                int tileX = colX - y * TILE_WIDTH / 2;
                int tileY = colY - y * TILE_HEIGHT_DIAMOND / 2;
                cache.add(texture, tileX, tileY, rand.nextInt(2) * 54, 0, TILE_WIDTH, TILE_HEIGHT);
            }
            colX += TILE_WIDTH / 2;
            colY -= TILE_HEIGHT_DIAMOND / 2;
        }
        layers[i] = cache.endCache();
    }
}
Also used : Random(java.util.Random) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 9 with OrthoCamController

use of com.badlogic.gdx.tests.utils.OrthoCamController in project libgdx by libgdx.

the class SimpleStageCullingTest method create.

@Override
public void create() {
    // create a stage and a camera controller so we can pan the view.
    stage = new Stage();
    ;
    // we know it's an ortho cam at this point!
    camController = new OrthoCamController((OrthographicCamera) stage.getCamera());
    Gdx.input.setInputProcessor(camController);
    // load a dummy texture
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    // populate the stage with some actors and groups.
    for (int i = 0; i < 5000; i++) {
        Actor img = new CullableActor("img" + i, texture, (OrthographicCamera) stage.getCamera());
        img.setX((float) Math.random() * 480 * 10);
        img.setY((float) Math.random() * 320 * 10);
        stage.addActor(img);
    }
    // we also want to output the number of visible actors, so we need a SpriteBatch and a BitmapFont
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 10 with OrthoCamController

use of com.badlogic.gdx.tests.utils.OrthoCamController 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

OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)16 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)15 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)13 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)13 Texture (com.badlogic.gdx.graphics.Texture)7 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)6 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)5 AssetManager (com.badlogic.gdx.assets.AssetManager)4 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)3 SpriteCache (com.badlogic.gdx.graphics.g2d.SpriteCache)2 MapLayers (com.badlogic.gdx.maps.MapLayers)2 AtlasTmxMapLoader (com.badlogic.gdx.maps.tiled.AtlasTmxMapLoader)2 TideMapLoader (com.badlogic.gdx.maps.tiled.TideMapLoader)2 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)2 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)2 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)2 IsometricTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer)2