Example usage for com.badlogic.gdx.graphics.g2d SpriteCache SpriteCache

List of usage examples for com.badlogic.gdx.graphics.g2d SpriteCache SpriteCache

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d SpriteCache SpriteCache.

Prototype

public SpriteCache(int size, boolean useIndices) 

Source Link

Document

Creates a cache with the specified size, using a default shader if OpenGL ES 2.0 is being used.

Usage

From source file:br.com.animvs.koalory.entities.engine.graphics.tiles.TileRenderer.java

License:Apache License

/**
 * @param cacheSize The maximum number of tiles that can be cached.
 *//*from   w ww.  j a  va2s .  co m*/
public TileRenderer(TiledMap map, float unitScale, int cacheSize, GameController controller) {
    this.map = map;
    this.unitScale = unitScale;
    spriteCache = new SpriteCache(cacheSize, true);
    this.controller = controller;
}

From source file:com.badlydrawngames.veryangryrobots.WorldView.java

License:Apache License

/** Constructs a new WorldView.
 * //from   ww w.  ja  v  a 2  s . c o  m
 * @param world the {@link World} that this is a view of.
 * @param presenter the interface by which this <code>WorldView</code> communicates the state of its controls. */
public WorldView(World world, StatusManager statusManager, Presenter presenter) {
    this.world = world;
    this.presenter = presenter;
    Rectangle bounds = world.getRoomBounds();
    worldMinX = bounds.x;
    worldMinY = bounds.y;
    worldWidth = bounds.width;
    worldHeight = bounds.height;
    worldMaxX = worldMinX + worldWidth;
    worldMaxY = worldMinY + worldHeight;
    // TODO: find some way of parameterising the viewport mode.
    worldCam = CameraHelper.createCamera2(ViewportMode.PIXEL_PERFECT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT,
            Assets.pixelDensity);
    worldCam.update();
    spriteBatch = new SpriteBatch();
    spriteCache = new SpriteCache(SPRITE_CACHE_SIZE, true);
    spriteBatch.setProjectionMatrix(worldCam.combined);
    spriteCache.setProjectionMatrix(worldCam.combined);
    prevSpriteCache = new SpriteCache(SPRITE_CACHE_SIZE, true);
    prevSpriteCache.setProjectionMatrix(worldCam.combined);
    cacheTransform = new Matrix4();
    prevCacheTransform = new Matrix4();
    touchPoint = new Vector3();
    dragPoint = new Vector3();
    joystick = new Vector2();
    particleManager = new ParticleManager(MAX_PARTICLES, PARTICLE_SIZE);
    particleAdapter = new ParticleAdapter(world, particleManager);
    world.addWorldListener(particleAdapter);
    flyupManager = new FlyupManager();
    statusManager.addScoringEventListener(flyupManager);
    resetCaches();
}

From source file:com.weimingtom.iteye.simplerpg.tiled.TileMapRenderer.java

License:Apache License

/** Initializer, used to avoid a "Constructor call must be the first statement in a constructor" syntax error when creating a
 * map from a TiledMap *///from ww  w . j  ava 2  s . c  o m
private void init(int[][][] map, TileAtlas atlas, int tileWidth, int tileHeight, float unitsPerTileX,
        float unitsPerTileY, IntArray blendedTiles, int tilesPerBlockX, int tilesPerBlockY,
        ShaderProgram shader) {
    this.atlas = atlas;
    this.tileWidth = tileWidth;
    this.tileHeight = tileHeight;
    this.unitsPerTileX = unitsPerTileX;
    this.unitsPerTileY = unitsPerTileY;

    this.blendedTiles = blendedTiles;
    this.tilesPerBlockX = tilesPerBlockX;
    this.tilesPerBlockY = tilesPerBlockY;

    unitsPerBlockX = unitsPerTileX * tilesPerBlockX;
    unitsPerBlockY = unitsPerTileY * tilesPerBlockY;

    isSimpleTileAtlas = atlas instanceof SimpleTileAtlas;

    int layer, row, col;

    allLayers = new int[map.length];

    // Calculate maximum cache size and map height in pixels, fill allLayers array
    int maxCacheSize = 0;
    int maxHeight = 0;
    int maxWidth = 0;
    for (layer = 0; layer < map.length; layer++) {
        allLayers[layer] = layer;
        if (map[layer].length > maxHeight)
            maxHeight = map[layer].length;
        for (row = 0; row < map[layer].length; row++) {
            if (map[layer][row].length > maxWidth)
                maxWidth = map[layer][row].length;
            for (col = 0; col < map[layer][row].length; col++)
                if (map[layer][row][col] != 0)
                    maxCacheSize++;
        }
    }
    mapHeightUnits = (int) (maxHeight * unitsPerTileY);
    mapWidthUnits = (int) (maxWidth * unitsPerTileX);

    if (shader == null)
        cache = new SpriteCache(maxCacheSize, false);
    else
        cache = new SpriteCache(maxCacheSize, shader, false);

    normalCacheId = new int[map.length][][];
    blendedCacheId = new int[map.length][][];
    for (layer = 0; layer < map.length; layer++) {
        normalCacheId[layer] = new int[(int) MathUtils.ceil((float) map[layer].length / tilesPerBlockY)][];
        blendedCacheId[layer] = new int[(int) MathUtils.ceil((float) map[layer].length / tilesPerBlockY)][];
        for (row = 0; row < normalCacheId[layer].length; row++) {
            normalCacheId[layer][row] = new int[(int) MathUtils
                    .ceil((float) map[layer][row].length / tilesPerBlockX)];
            blendedCacheId[layer][row] = new int[(int) MathUtils
                    .ceil((float) map[layer][row].length / tilesPerBlockX)];
            for (col = 0; col < normalCacheId[layer][row].length; col++) {
                if (isSimpleTileAtlas) {
                    // Everything considered blended
                    blendedCacheId[layer][row][col] = addBlock(map[layer], row, col, false);
                } else {
                    normalCacheId[layer][row][col] = addBlock(map[layer], row, col, false);
                    blendedCacheId[layer][row][col] = addBlock(map[layer], row, col, true);
                }
            }
        }
    }
}