1

I've come across those articles: https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/assets/AssetManager.html http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/assets/loaders/PixmapLoader.html http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/assets/loaders/TextureLoader.html https://github.com/libgdx/libgdx/wiki/Managing-your-assets

And I still didn't find anything about how to load a Texture into the AssetManager. In my game I create a Pixmap and wrap it around a Texture. Then I dispose the Pixmap. Then I draw the Texture with SpriteBatch. Every Texture created in my game has been created by a Pixmap, so it's created in runtime. How do I load those Textures into the AssetManager?

The links above and everything I've come across only show how to load Textures from already available files.

  • Check the AssetManager docs. It is all covered there – Zoe Sep 07 '17 at 15:19
  • You don't need to load those assets as you created them at runtime and are already loaded. So why would you need to use an asset manager? – dfour Sep 07 '17 at 15:25
  • @LunarWatcher as stated above, I've read all docs available or googled hours since. It's actually not covered good enough with examples for what I need. – Manh Khôi Duong Sep 08 '17 at 00:10
  • @dfour To prevent it from loading again. AssetManager can be helpful to prevent taking up memory twice or more. – Manh Khôi Duong Sep 08 '17 at 00:12
  • @LunarWatcher you definitely didn't understand or even read my question above. Because using load() is to load from already available files! But my textures etc. are made during the runtime (!) which is very different. I spend hours to read and nowhere is described how to load ressources from runtime! Instead of telling me that I didn't read well or downvote my question, you could be helping me by explaining what I should do (if you know better but I doubt that). You are very rude – Manh Khôi Duong Sep 08 '17 at 13:16
  • @LunarWatcher I've described how I created my Texture above. Take your time and read my question before spamming here. – Manh Khôi Duong Sep 19 '17 at 01:12

1 Answers1

2

From your comment

AssetManager can be helpful to prevent taking up memory twice or more.

You probably don't need to use asset manager to prevent this from happening. Instead you can just add a conditional in your code that checks if the asset is already loaded e.g.

if(myTexture != null){
    // not loaded
    pmap = new Pixmap(10, 10,Format.RGBA8888);
    pmap.setColor(Color.RED);
    pmap.fill();
    myTexture = new Texture(pmap);
    pmap.dispose()
}else{
    // already loaded, do nothing (or add to count of times used)
}

If you still want to use asset manager you have a couple of options.

  1. You can save your current texture/pixmap images into actual files an load them normally with the asset manager. (simplest option)
  2. Extend the AssetManager (code) and add your own method to add your assets to the assets objectMap and assetTypes objectMap.
dfour
  • 1,376
  • 1
  • 12
  • 16
  • Solution 2 sounds fine to me. I want to work with the assetManager since I can pass that around from switching between Screens. A conditional loop wouldn't be so great because I'd have to do that to every ressource available in my game. I will try solution 2 and till it work I'll check your answer as the solution. – Manh Khôi Duong Sep 08 '17 at 13:23