LibGDX TextureAtlas

I want to batch texture by using TextureAtlas.

However, I’m not sure if using addRegion(name, TextureRegion) works as if the textures are all one.

Will using TextureAtlas in this way give me packed texture performance?

A TextureRegion is (as the name suggests) just a region of a texture. I am not sure what you mean with “as if the textures are all one”. A TextureRegion just holds 1 texture and defines a rectangular area of that texture.

I mean will adding textures to a TextureAtlas be as optimized as drawing TextureRegions from a single Texture. Or even better, explain a TextureAtlas.

TextureAtlas is ONE texture, that is made up of 1 or more smaller textures.

For example, if you have 4 textures that are 32x32, don’t create 4 different texture objects, but instead, pack them into a TextureAtlas using this handy tool here:
https://code.google.com/p/libgdx-texturepacker-gui/

It will create a single texture file, and also create a .pack file which holds data such as the texture location, and name (along with other settings such as padding etc).

If you wanted to create a textureAtlas, first download that GUI tool from above and create a TextureAtlas and pack file from it (there are videos showing how, use your google-fu).
Lets just say you have four 32x32 image that you put into the texturePacker, called grasstile, sandtile, watertile, mountaintile, it would pack them all in one texture that is then 64x64 in size, or 128x32, or 96x64, or whatever depending on how you want to pack them.
It also uses the file names of the 32x32 images to use as reference inside your code

Then create a TextureAtlas object, followed by a sprite that you can easily recognize, like so:

public class WorldRenderer implements Screen{

TextureAtlas atlas;
Sprite grass; //do the same thing with other textures

Then under your constructor, you want to do the following:

public WorldRenderer(World world){
		this.world = world;

atlas = new TextureAtlas(Gdx.files.internal("data/terraintiles.pack")); //point this towards your .pack file
grass = atlas.createSprite("grasstile"); //this is the name of the file you put into your textureAtlas, the texturepacker names that texture region with the filename so it's easy to refer to.

Then inside of your render() method, and inside of your batch.draw(); do the following:

public void render(){

batch.begin();
batch.draw(grass, posX, posY, scaleX, scaleY); //draw the grass sprite, set it's x and y positions, and the scale of the sprite in X and Y

I am using the pixmappacker for creating the textureatlas: http://www.badlogicgames.com/wordpress/?p=2297

Close, but nope. TextureAtlas is a map where keys are a name and the value is a TextureRegion. The regions do not need to be in the same texture. When TextureAtlas loads from a libgdx format atlas file, it can load regions from multiple pages of images.

To answer the OP, adding a region to a TextureAtlas is the same as if it were loaded by an atlas file. Once you get the regions and draw them, performance may be affected by texture switching if using multiple atlas pages, but TextureAtlas isn’t involved. It is just a map, it doesn’t have anything to do with drawing.