Search in sources :

Example 1 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 2 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 3 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 4 with OrthoCamController

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

the class ETC1Test method create.

@Override
public void create() {
    font = new BitmapFont();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    controller = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(controller);
    Pixmap pixmap = new Pixmap(32, 32, Format.RGB565);
    pixmap.setColor(1, 0, 0, 1);
    pixmap.fill();
    pixmap.setColor(0, 1, 0, 1);
    pixmap.drawLine(0, 0, 32, 32);
    pixmap.drawLine(0, 32, 32, 0);
    ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap);
    pixmap.dispose();
    pixmap = ETC1.decodeImage(encodedImage, Format.RGB565);
    encodedImage.dispose();
    img1 = new Texture(pixmap);
    img2 = new Texture("data/test.etc1");
    batch = new SpriteBatch();
    pixmap.dispose();
}
Also used : ETC1Data(com.badlogic.gdx.graphics.glutils.ETC1.ETC1Data) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 5 with OrthoCamController

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

the class TiledMapBench method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 320, 320);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    {
        tiles = new Texture(Gdx.files.internal("data/maps/tiled/tiles.png"));
        TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32);
        map = new TiledMap();
        MapLayers layers = map.getLayers();
        for (int l = 0; l < 20; l++) {
            TiledMapTileLayer layer = new TiledMapTileLayer(150, 100, 32, 32);
            for (int x = 0; x < 150; x++) {
                for (int y = 0; y < 100; y++) {
                    int ty = (int) (Math.random() * splitTiles.length);
                    int tx = (int) (Math.random() * splitTiles[ty].length);
                    Cell cell = new Cell();
                    cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx]));
                    layer.setCell(x, y, cell);
                }
            }
            layers.add(layer);
        }
    }
    renderer = new OrthogonalTiledMapRenderer(map);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapLayers(com.badlogic.gdx.maps.MapLayers)

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