Search in sources :

Example 1 with SpriteCache

use of com.badlogic.gdx.graphics.g2d.SpriteCache 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 2 with SpriteCache

use of com.badlogic.gdx.graphics.g2d.SpriteCache in project libgdx by libgdx.

the class SpriteCacheTest method create.

@Override
public void create() {
    spriteCache = new SpriteCache(1000, true);
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
    pixmap.setColor(1, 1, 0, 0.5f);
    pixmap.fill();
    texture2 = new Texture(pixmap);
    pixmap.dispose();
    sprites = new float[SPRITES * 6];
    sprites2 = new float[SPRITES * 6];
    Sprite[] sprites3 = new Sprite[SPRITES * 2];
    for (int i = 0; i < sprites.length; i += 6) {
        sprites[i] = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        sprites[i + 1] = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        sprites[i + 2] = 0;
        sprites[i + 3] = 0;
        sprites[i + 4] = 32;
        sprites[i + 5] = 32;
        sprites2[i] = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        sprites2[i + 1] = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        sprites2[i + 2] = 0;
        sprites2[i + 3] = 0;
        sprites2[i + 4] = 32;
        sprites2[i + 5] = 32;
    }
    for (int i = 0; i < SPRITES * 2; i++) {
        int x = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        int y = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        if (i >= SPRITES)
            sprites3[i] = new Sprite(texture2, 32, 32);
        else
            sprites3[i] = new Sprite(texture, 32, 32);
        sprites3[i].setPosition(x, y);
        sprites3[i].setOrigin(16, 16);
    }
    float scale = 1;
    float angle = 15;
    spriteCache.beginCache();
    for (int i = 0; i < sprites2.length; i += 6) spriteCache.add(texture2, sprites2[i], sprites2[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, false, false);
    for (int i = 0; i < sprites.length; i += 6) spriteCache.add(texture, sprites[i], sprites[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, false, false);
    normalCacheID = spriteCache.endCache();
    angle = -15;
    spriteCache.beginCache();
    for (int i = SPRITES; i < SPRITES << 1; i++) {
        sprites3[i].setRotation(angle);
        sprites3[i].setScale(scale);
        spriteCache.add(sprites3[i]);
    }
    for (int i = 0; i < SPRITES; i++) {
        sprites3[i].setRotation(angle);
        sprites3[i].setScale(scale);
        spriteCache.add(sprites3[i]);
    }
    spriteCacheID = spriteCache.endCache();
    Gdx.input.setInputProcessor(this);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 3 with SpriteCache

use of com.badlogic.gdx.graphics.g2d.SpriteCache in project libgdx by libgdx.

the class TileTest method create.

@Override
public void create() {
    cam = new OrthographicCamera(480, 320);
    cam.position.set(WIDTH * 32 / 2, HEIGHT * 32 / 2, 0);
    camController = new OrthoCamController(cam);
    Gdx.input.setInputProcessor(camController);
    texture = new Texture(Gdx.files.internal("data/tiles.png"));
    Random rand = new Random();
    for (int i = 0; i < LAYERS; i++) {
        caches[i] = new SpriteCache();
        SpriteCache cache = caches[i];
        cache.beginCache();
        for (int y = 0; y < HEIGHT; y++) {
            for (int x = 0; x < WIDTH; x++) {
                int tileX = rand.nextInt(5);
                int tileY = rand.nextInt(5);
                cache.add(texture, x << 5, y << 5, 1 + tileX * 33, 1 + tileY * 33, 32, 32);
            }
        }
        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)

Example 4 with SpriteCache

use of com.badlogic.gdx.graphics.g2d.SpriteCache in project libgdx by libgdx.

the class SpriteCacheOffsetTest method create.

public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    Sprite sprite = new Sprite(texture);
    sprite.setSize(tileSize, tileSize);
    cache = new SpriteCache(1000, false);
    for (int y = 0; y < tileMapHeight; y++) {
        cache.beginCache();
        for (int x = 0; x < tileMapWidth; x++) {
            sprite.setPosition(x * tileSize, y * tileSize);
            cache.add(sprite);
        }
        cache.endCache();
        sprite.rotate90(true);
    }
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache) Texture(com.badlogic.gdx.graphics.Texture)

Example 5 with SpriteCache

use of com.badlogic.gdx.graphics.g2d.SpriteCache in project libgdx by libgdx.

the class IsometricTileTest method dispose.

@Override
public void dispose() {
    renderer.dispose();
    texture.dispose();
    for (SpriteCache cache : caches) cache.dispose();
}
Also used : SpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache)

Aggregations

SpriteCache (com.badlogic.gdx.graphics.g2d.SpriteCache)8 Texture (com.badlogic.gdx.graphics.Texture)4 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)2 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)2 Random (java.util.Random)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1