Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX TextureAtlas  (Read 1557 times)
0 Members and 1 Guest are viewing this topic.
Offline KudoDEV

JGO Knight

Medals: 54
Exp: 6 years

Game Dev Hobbyist

« Posted 2013-08-10 19:05:20 »

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?

Offline sirkarpfen

Junior Devvie

Medals: 2
Exp: 2 years

« Reply #1 - Posted 2013-08-10 21:01:01 »

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.
Offline KudoDEV

JGO Knight

Medals: 54
Exp: 6 years

Game Dev Hobbyist

« Reply #2 - Posted 2013-08-11 02:46:09 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Otreum

Junior Devvie

Medals: 6

« Reply #3 - Posted 2013-08-11 05:02:23 »

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:

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){ = 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.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
Offline Phibedy

Senior Devvie

Medals: 9

« Reply #4 - Posted 2013-08-11 09:37:48 »

I am using the pixmappacker for creating the textureatlas:
Offline Nate

« JGO Bitwise Duke »

Medals: 165
Projects: 4
Exp: 14 years

Esoteric Software

« Reply #5 - Posted 2013-08-11 17:47:24 »

TextureAtlas is ONE texture, that is made up of 1 or more smaller textures.
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.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (21 views)
2015-08-04 11:03:17

SHC (39 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (51 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!