Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've searched around for tutorials. I've seen people using the above classes to load images.

As according to my understanding, all of the classes can read in a non-power of two images, TextureRegion/TextureAtlas are usually used to load sprite sheet, in which the sheet contains multiple images. While for Texture/Sprite/Image, they are used to load a sprite sheet with single image.

However, I'm not so sure in which situation I should use Texture/Sprite/Image and in which situation I should use TextureRegion/TextureAtals.

Please correct me if I'm wrong, as I'm a bit confused by the terminologies in the API after looking various tutorials.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

First, Texture vs TextureRegion: When you do something like Texture t = new Texture(path), you are loading that into GPU. In addition, you should load power of 2 textures. You could work with other resolutions (Texture.setEnforcePotImages = false), but it's encouraged to use pow of 2.

Now, TextureRegion, takes a "piece" from a Texture, no matter it's dimension. The advantage of having one Texture and multiple TextureRegion of that Texture, is that you are NOT loading every region into GPU.

As you may be thinking, when you want to draw with the SpriteBatch, it's much more efficient to use TextureRegion instead of multiple Textures, I'm sorry my english is not good enough. Here is a good explanation: Textures TextureRegion & SpriteBatch


Now, you want to use TextureRegion and one single image in power of 2 resolution with all the spritesheets and images. Do you have to create TextureRegions with all the coordinates and dimensions? Do you need to open paint to count pixels? Noooo, you don't. You can use something like TexturePacker. It will pack every texture into one image AND create a .pack file with de dimensions and coordinates of all of them.

TexturePacker

The result will be something like this:

Pack

Instead of creating a Texture, create a TextureAtlas, like this:

Create TextureAtlas

Now, creating your TextureRegions would be as simple as:

findRegion

(Note that the name of the region is the name of the original image without the extension).


Sprite holds the geometry, color, and texture information for drawing 2D sprites using Batch. This mean, you can easily rotate them and move. I've created my own Entity class, and I don't need Sprite class. You would probably do the same. I don't find this class really usefull.


Image class inherits from Actor. This mean you can add it into a stage. It's part of the Scene2D package. If your are new to libgdx, and you don't know about this package, this is enough information for you about this class. It's a really interesting topic, but not to answer in this question.

Hope it helps :)

share|improve this answer
    
Thanks! That's clearer now. :) Then what about the performance of creating TextureRegion from Texture and creating TextureRegion from TextureAtlas? –  user15783 Dec 1 '13 at 14:33
1  
@user15783 Ask as a new question. –  David J. Liszewski Dec 1 '13 at 15:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.