Example usage for com.badlogic.gdx.graphics.g2d TextureRegion split

List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion split

Introduction

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

Prototype

public static TextureRegion[][] split(Texture texture, int tileWidth, int tileHeight) 

Source Link

Document

Helper function to create tiles out of the given Texture starting from the top left corner going to the right and ending at the bottom right corner.

Usage

From source file:spaceisnear.game.objects.items.ItemsArchive.java

public ItemsArchive(ItemBundle[] bundles) {
    super(bundles);
    sprites = new Texture(Gdx.files.classpath("res").child("sprites.png"));
    TextureRegion[][] split = TextureRegion.split(sprites, GameContext.TILE_WIDTH, GameContext.TILE_HEIGHT);
    regions = new TextureRegion[split.length * split[0].length];
    int index = 0;
    for (TextureRegion[] textureRegions : split) {
        for (TextureRegion textureRegion : textureRegions) {
            textureRegion.flip(false, true);
            regions[index++] = textureRegion;
        }//from  www. ja  va 2  s.  c  om
    }
}