Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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 762 times)
0 Members and 1 Guest are viewing this topic.
Offline KudoDEV

Senior Newbie





« Posted 2013-08-10 21: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 Member


Medals: 2
Exp: 2 years



« Reply #1 - Posted 2013-08-10 23: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

Senior Newbie





« Reply #2 - Posted 2013-08-11 04: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 Member


Medals: 6



« Reply #3 - Posted 2013-08-11 07: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:
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:
1  
2  
3  
4  
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:
1  
2  
3  
4  
5  
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:
1  
2  
3  
4  
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
Offline Phibedy

Senior Member


Medals: 8



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

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

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2013-08-11 19: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (11 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (8 views)
2014-07-29 10:59:34

E.R. Fleming (25 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!