Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Textures loaded using AssetManager do not appear on screen  (Read 521 times)
0 Members and 1 Guest are viewing this topic.
Offline mmx358

Junior Newbie


Exp: 3 years



« Posted 2017-08-04 10:03:44 »

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:
1  
2  
3  
4  
5  
6  
assetManager.load(BALL, Texture.class);
assetManager.load(BRICK, Texture.class);
assetManager.load(PADDLE, Texture.class);
assetManager.finishLoading();

// Then I load some fonts


Constructing sprites:
1  
2  
3  
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:
1  
2  
3  
4  
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:
1  
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.
Offline dfour
« Reply #1 - Posted 2017-08-04 11:02:13 »

Hey @mmx358,

I can't see anything wrong with the code you provided, I suspect it may be down to when you are loading and assigning the images.

You can check if the images have loaded with
1  
2  
3  
if(manager.isLoaded("data/mytexture.png")) {
    // image loaded to set it as sprite
}


Quote
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.

I have a guide on my blog for the Asset Manager which can be used for more than just textures. As well as the Texture packer which is a great tool for packing lots of images into a single atlas. These are great when used together as it allows you to have a pack for your loading screen, a pack for your game assets and a pack for GUI etc which can be loaded or unloaded separately.
Offline phunni

Senior Newbie


Exp: 17 years



« Reply #2 - Posted 2017-08-04 13:47:22 »

I very much doubt it'll make a difference (I haven't looked at the source), but the get() method on AssetManager doesn't have to take a class type. I can't see why not including it would help, although I also can't see why your code wouldn't work - it's pretty much the same as I've got in my Asset loading class...

I also second the recommendation to use TexturePacker (although I'd suggest the newer one.)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mmx358

Junior Newbie


Exp: 3 years



« Reply #3 - Posted 2017-08-04 20:45:06 »

I can't see anything wrong with the code you provided, I suspect it may be down to when you are loading and assigning the images.

You can check if the images have loaded with
1  
2  
3  
if(manager.isLoaded("data/mytexture.png")) {
    // image loaded to set it as sprite
}

dfour, isLoaded returns true in my case.  Undecided

I have a guide on my blog for the Asset Manager which can be used for more than just textures. As well as the Texture packer which is a great tool for packing lots of images into a single atlas. These are great when used together as it allows you to have a pack for your loading screen, a pack for your game assets and a pack for GUI etc which can be loaded or unloaded separately.
Thank You for this advice, I'll try that during "polishing phase".

I very much doubt it'll make a difference (I haven't looked at the source), but the get() method on AssetManager doesn't have to take a class type. I can't see why not including it would help, although I also can't see why your code wouldn't work - it's pretty much the same as I've got in my Asset loading class...

I also second the recommendation to use TexturePacker (although I'd suggest the newer one.)


I very much doubt it'll make a difference (I haven't looked at the source), but the get() method on AssetManager doesn't have to take a class type.
I can't see why not including it would help, although I also can't see why your code wouldn't work - it's pretty much the same as I've got in my Asset loading class...
I use it because without class type it should be explicitly cast to a Texture class, which is "dirty style" in my opinion... Anyway, this does not help.

I also second the recommendation to use TexturePacker (although I'd suggest the newer one.)
Okay, thank You too, I'll definitely incorporate this technique after some time.


I think I should do some "experiments" with different order of loading assets, different texture image formats and so on. Probably this will happen few days later because of other things to do.
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (13 views)
2017-11-21 16:21:00

xxMrPHDxx (10 views)
2017-11-21 16:14:31

xxMrPHDxx (10 views)
2017-11-21 16:10:57

Ecumene (113 views)
2017-09-30 02:57:34

theagentd (148 views)
2017-09-26 18:23:31

cybrmynd (246 views)
2017-08-02 12:28:51

cybrmynd (242 views)
2017-08-02 12:19:43

cybrmynd (242 views)
2017-08-02 12:18:09

Sralse (257 views)
2017-07-25 17:13:48

Archive (875 views)
2017-04-27 17:45:51
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!