I got to that point when I have to replace all new Sprite(texture) with new Sprite(manager.get(imgPath,Texture.class)) in order to optimize sprites creating and do all the loading before starting the game.
The problem is that when I use a common AssetManager to load all textures I get black rectangles.
Still, using a new AssetManager() each time I need to load a Texture works fine (maybe because this manager is quickly garbadge-collected and doesn't have time to dispose the texture it created?) but that way there is no point of using it.
The setupBody() method below is called at the end of my sprite-body wrapper constructor.
the working code (yet useless) ─ one new AssetManager for each sprite:
protected void setupBody(String path){
BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal(path));
BodyDef bDef = new BodyDef();
bDef.type = BodyDef.BodyType.DynamicBody;
bDef.position.set(this.position);
bDef.angle = this.rotation;
body = mWorld.createBody(bDef);
body.setUserData(this);
FixtureDef fix = new FixtureDef();
fix.density = 0.1f;
fix.friction = 0f;
fix.restitution = 0.5f;
fix.filter.categoryBits = this.getCategory();
fix.filter.maskBits = this.getMask();
origin = loader.getOrigin("base"+identifier, 1).cpy();
String imgPath = loader.getImagePath("base"+identifier);
AssetManager manager = new AssetManager();
manager.load(imgPath,Texture.class);
manager.finishLoading();
Texture baseSpriteTexture = manager.get(imgPath,Texture.class);
Texture baseSpriteTexture = new Texture(imgPath);
baseSprite = new Sprite(baseSpriteTexture);
loadHighlightedSprite(loader, identifier);
attachFixture(loader, identifier, fix);
}
the code keeping me sleepless ─ the idea is to have a single non-static manager :
protected void setupBody(String path){
/*no changes before */
String imgPath = loader.getImagePath("base"+identifier);
AssetManager manager = SmallIntestineDemoGame.getAssets();
manager.load(imgPath,Texture.class);
/* no changes after */
}
SmallIntestineDemoGame$getAssets() :
public class SmallIntestineDemoGame extends Game {
public AssetManager assets;
@Override
public void create() {
setScreen(new GameScreen());
}
public static AssetManager getAssets() {
return ((SmallIntestineDemoGame) Gdx.app.getApplicationListener()).assets;
}
public void setupAssets(){
this.assets = new AssetManager();
Texture.setAssetManager(assets);
}
}
DEBUGGING :
Debugging my asset manager got me confused. size of values of values of assets map of manager gets stuck at 33 even if I'm adding more:

(source: hostingpics.net)
I tested both cases ─ the app with a new AssetManager() (followed by finishloading and all required stuff) for each sprite creation. AND with a unique asset manager passed to all sprite creations :
I set a breakpoint at draw method and there was almost no difference between the two sprites, except for sprite.texture.glhandle ! When all sprites textures are created using the same manager their textures glhandle is set to 0 and this explains the black rectangles. But when each sprite is created using a locally newly created asset manager, the glhandle has some proper value (2269).