Skip to content

Instantly share code, notes, and snippets.

@loriopatrick
Created October 12, 2014 07:36
Show Gist options
  • Save loriopatrick/cba1f0e03e9b8888c234 to your computer and use it in GitHub Desktop.
Save loriopatrick/cba1f0e03e9b8888c234 to your computer and use it in GitHub Desktop.
TextureRegion
TextureRegion[][] parts = TextureRegion.split(new Texture("path.png"), 15, 23);
boolean[][] used = new boolean[parts.length][parts[0].length];
Random random = new Random();
int ix = random.nextInt(used.length);
int iy = random.nextInt(used[0].length);
while (used[ix][iy]) {
// todo: pick new
}
SpriteBatch spriteBatch = new SpriteBatch();
spriteBatch.begin();
spriteBatch.draw(parts[ix][ix], parts[0][0].getRegionWidth() * ix, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment