Hi friends!
I’m working on a breakout clone to learn game development basics and have strange trouble with loading resources. Loading fonts from “.ttf” files works and I can use them without any problems. Looks like textures are loaded successfully (no exceptions), but when I draw a texture, It can’t be seen on a screen, in other words, the screen is black. At the same time, when I load the texture using Gdx.files.internal(“bla/bla.png”), it is displayed on the screen. What the hell?
Here goes some code, don’t know if it is enough.
Loading textures via AssetManager:
assetManager.load(BALL, Texture.class);
assetManager.load(BRICK, Texture.class);
assetManager.load(PADDLE, Texture.class);
assetManager.finishLoading();
// Then I load some fonts
Constructing sprites:
ball = new Sprite(assetManager.get(BALL, Texture.class));
brick = new Sprite(assetManager.get(BRICK, Texture.class)); //BRICK == "textures/brick.png"
paddle = new Sprite(assetManager.get(PADDLE, Texture.class));
Both ways do not work:
brick.setPosition(10, 10);
brick.draw(batch);
batch.draw(brick.getTexture(), 2, 2);
BUT if I load brick’s texture like this, it’s being properly displayed:
brick = new Sprite(new Texture(Gdx.files.internal("textures/brick.png")));
That’s it… I’ll continue development using Gdx.files.internal(…) just because it doesn’t really matter that much, I need just three textures in a single class (GameScreen). But I’d like to know how to deal with this issue to write as good code as possible for a simple game and to get advantage of AssetManager for a complex one with large number of different textures.