1
votes

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.

1
Check the AssetManager docs. It is all covered thereZoe
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
@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
@dfour To prevent it from loading again. AssetManager can be helpful to prevent taking up memory twice or more.Manh Khôi Duong
@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 rudeManh Khôi Duong

1 Answers

2
votes

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.