Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (723)
Games in Android Showcase (216)
games submitted by our members
Games in WIP (790)
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  
  [Best practice]Assetmanager vs TextureAtlas  (Read 779 times)
0 Members and 1 Guest are viewing this topic.
Offline Hades85

Senior Newbie





« Posted 2017-04-09 22:49:28 »

At the moment i use both in combination but i think in a wrong way:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public class Assets {

   public static final AssetManager manager = new AssetManager();

   public static final String player = "hero/hero.txt";
   public static final String pogo = "enemy/pogopuschel.txt";

   public static void load() {
     
      manager.load(player, TextureAtlas.class);
      manager.load(pogo, TextureAtlas.class);
   }

   public static void dispose() {
      manager.dispose();
   }
}


PlayScreen class
1  
2  
3  
4  
5  
public PlayScreen(Main game) {
      Assets.load();
      Assets.manager.finishLoading();
      atlas = Assets.manager.get(Assets.player, TextureAtlas.class); //Load only one Asset, how to load more?
}


Player class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public Player(PlayScreen screen) {
      super(screen);
     
     
      move_down    = setAnimation(super.move_down, 32, 32, false);
      move_up      = setAnimation(super.move_up, 32, 32, false);  
      move_right   = setAnimation(super.move_right, 32, 32, false);
      move_left   = setAnimation(super.move_right, 32, 32, true);
     
      stand_down    = new TextureRegion(screen.getAtlas().findRegion(super.stand_down), 0, 0, 32, 32);
      stand_up    = new TextureRegion(screen.getAtlas().findRegion(super.stand_up), 0, 0, 32, 32);
      stand_right = new TextureRegion(screen.getAtlas().findRegion(super.stand_right), 0, 0, 32, 32);
      stand_left    = new TextureRegion(screen.getAtlas().findRegion(super.stand_right), 0, 0, 32, 32);
      stand_left.flip(true, false);
     
     
   }


I have a lot of sprites maybe over 2000 can i only use TexturePacker and TextureAtlas? Or should i use the Assetmanager in combination?

How can i give the TextureAtlas all Assets from the AssetManager?
Offline dfour
« Reply #1 - Posted 2017-04-10 09:17:54 »

You appear to be using the asset manager correctly.

Quote
How can i give the TextureAtlas all Assets from the AssetManager?

I assume by this you mean how do you put all images into one atlas?

You can use a texture packer to pack all your images into a larger file.

A guide on AssetManager https://www.gamedevelopment.blog/asset-manager-libgdx-tutorial/

A guide on Texture Packer  https://www.gamedevelopment.blog/texture-packer-gui-quick-tutorial/
Offline Hades85

Senior Newbie





« Reply #2 - Posted 2017-04-10 13:44:40 »

Thx for the links.

But what is the maximum size for textureatlas?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dfour
« Reply #3 - Posted 2017-04-10 17:50:17 »

Quote
But what is the maximum size for textureatlas?

You can put as many images as you want into an atlas but you should try and keep the atlas size 1024 x 1024 for maximum compatibility but 2048 x 2048 will work on most devices.

If you have too many images to fit onto a single 1024x1024 image then you can use split the atlas into several pages of 1024x124
Offline Hades85

Senior Newbie





« Reply #4 - Posted 2017-04-10 22:38:42 »

If i split them into more images, is it usefull to instantiate more TextureAtlas class as one?

Thanks for your help.
Offline dfour
« Reply #5 - Posted 2017-04-11 09:20:39 »

The main reason to put all your images in a TextureAtlas is to keep as many images as possible in a single image so you only need to read the image file from disk once which is slow. Then when you want a single image you read it from the already loaded TextureAtlas which is loaded in memory which is a lot faster. So in terms of performance, you are best off having as few as possible Images to load from disk.

Usually, if you have a lot of images that won't fit onto a single 1024x1024 image you would pack them onto multiple 1024x1024 pages all in the same atlas. This would give you one atlas(information on individual images) and several 1024x1024 image files that belong  to that atlas.

Offline ClaasJG

JGO Coder


Medals: 41



« Reply #6 - Posted 2017-04-11 14:47:13 »

It is not about disc load time but about minimizing opengl texture switching.
You want to minimize the render state changes between different objects so you can minimize your draw calls.

My english has to be tweaked. Please show me my mistakes.
Offline Hades85

Senior Newbie





« Reply #7 - Posted 2017-04-13 08:25:40 »

Sorry again, do i need to create a multiple packages in Texture Packer?
I cant find any Method from TextureAtlas to load more than one Image.
Offline dfour
« Reply #8 - Posted 2017-04-13 08:35:02 »

In Libgdx, the asset manager will load all the pages that belong to the atlas automatically as long as they're numbered.
So for gui.atlas all gui_1.png, gui_2.png and gui_3.png will be loaded.

Have you tried to load a single atlas with multiple pages then use an image from each page? Would be a good way to check if it's working.
Offline Hades85

Senior Newbie





« Reply #9 - Posted 2017-04-13 08:49:13 »

Maybe i miss understand you but i dont load any png file with assetmanager. Only that txt file from TexturPacker:
1  
2  
3  
4  
5  
6  
7  
8  
public static final String player = "hero/split.txt";
public static final String pogo = "enemy/pogopuschel.txt";

   public static void load() {
     
      manager.load(player, TextureAtlas.class);
      manager.load(pogo, TextureAtlas.class);
   }


And that txt file reference to the image regions.

So i dont understand how to load more than more file to the textureAtlas when i need more than one 1024x1024 image.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dfour
« Reply #10 - Posted 2017-04-13 09:20:17 »

The text file is also known as an atlas, this text file has the names of all the image files it needs and so when the assetManager loads the text file it will find the names of the images needed and load them.

This is an excerpt of a text file for some packed images from my pet project:

Quote
loadingGui.png
format: RGBA8888
filter: MipMapLinearLinear,MipMapLinearLinear
repeat: none
blockBreakerTitle
  rotate: false
  xy: 2, 109
  size: 960, 145
  orig: 960, 145
  offset: 0, 0
  index: -1

As you can see on the first few lines is the name of the image which contains all the smaller images as well as some image type information. From blockBreakerTitle until the end is one of the images that was packed. It says where this smaller image can be found on the packed image as well as it's size and offset. The final attribute "index" is to say which page the image is on. This package only has 1 image so -1 is used but if there was more images the index of the page it is on would be used.
Offline Hades85

Senior Newbie





« Reply #11 - Posted 2017-04-13 09:36:40 »

Ah ok, i think i got it.

atlas.findRegion(name, index) // now i understand for what the index is.

I only load one txt file into the assetmanger for all my images, right?

Ok, but now i dont understand why using the assetmanger? Why not using at the programm start only TextureAtlas? Once loaded no need of assetManager.
Offline dfour
« Reply #12 - Posted 2017-04-13 09:49:11 »

The assetManager not only loads image files, but sounds, music, particleEffects, fonts, skins etc. It also keeps track of all of the items it loads and won't dispose of the item until all references of it are no longer needed as well as only loading a single item once even if asked to load it twice as it knows it already has one reference to that item. Finally it allows you to load items asynchronously so you can make cool loading screens with progress bars Smiley
Offline Hades85

Senior Newbie





« Reply #13 - Posted 2017-04-13 10:00:08 »

Thank you so much! Smiley

At the moment i use more than one Assetmanager , one for music, one for images and so on. I will merge them into one assetmanager.

Pages: [1]
  ignore  |  Print  
 
 

 
buddyBro (188 views)
2017-04-05 03:38:00

CopyableCougar4 (618 views)
2017-03-24 15:39:42

theagentd (611 views)
2017-03-24 15:32:08

Rule (662 views)
2017-03-19 12:43:22

Rule (636 views)
2017-03-19 12:42:17

Rule (640 views)
2017-03-19 12:36:21

theagentd (652 views)
2017-03-16 05:07:07

theagentd (586 views)
2017-03-15 22:37:06

theagentd (426 views)
2017-03-15 22:32:18

theagentd (355 views)
2017-03-15 22:31:11
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!