AssetsManager [No loader for type: TextureRegion]

Anything libgdx related goes here!

AssetsManager [No loader for type: TextureRegion]

Postby TruePlayer » Thu Sep 12, 2019 5:52 pm

I get an error when loading a background image, why is this happening?
I checked the file there is definitely there)
I do not use capital letters or spaces in the file path
app.assetManager.load("textures/back.png", TextureRegion.class); - this line error: "app.assetManager.load("textures/back.png", TextureRegion.class);"



Code: Select all
public class LoadingView implements Screen {

    private Main app;
    private ShapeRenderer shapeRenderer;


    public LoadingView(final Main app){
        this.app = app;
        shapeRenderer = new ShapeRenderer();

        queueAssets();
    }


    private void update(float delta){
        if (app.assetManager.update()){
            app.setScreen(new MenuView(app.getGsm()));
        }
    }

    private void queueAssets() {
        app.assetManager.load("textures/back.png", TextureRegion.class);
    }

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        update(delta);
    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: AssetsManager [No loader for type: TextureRegion]

Postby evilentity » Thu Sep 12, 2019 7:17 pm

Its exactly what it says, there is no loader for TextureRegion. You cant load a TextureRegion, its by definition a region of a Texture, which you can load.
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4851
Joined: Wed Aug 24, 2011 11:37 am

Re: AssetsManager [No loader for type: TextureRegion]

Postby TruePlayer » Thu Sep 12, 2019 8:09 pm

I changed to a simple texture and get another error already
Code: Select all
 background = game.assetManager.get("textures/back.png", Texture.class);

Asset not loaded: textures/back.png
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: AssetsManager [No loader for type: TextureRegion]

Postby evilentity » Thu Sep 12, 2019 8:21 pm

Well then, did you load it? As your method says, queueAssets, not loadAssets. You seem to be updating the manager.

Anyway, for splash screen you can probably just do new Texture() and draw it while stuff loads. Just make sure to dispose it when you hide the screen.
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4851
Joined: Wed Aug 24, 2011 11:37 am

Re: AssetsManager [No loader for type: TextureRegion]

Postby yobowargames » Thu Sep 12, 2019 8:45 pm

Read this page on how to load, check progress and confirm loaded before using your assets:

https://github.com/libgdx/libgdx/wiki/M ... our-assets
yobowargames
 
Posts: 11
Joined: Sat Oct 27, 2018 4:25 pm

Re: AssetsManager [No loader for type: TextureRegion]

Postby TruePlayer » Thu Sep 12, 2019 8:48 pm

yobowargames wrote:Read this page on how to load, check progress and confirm loaded before using your assets:

https://github.com/libgdx/libgdx/wiki/M ... our-assets


I did it right away


I try to read more articles from github, rather than wasting other people's time. I do everything according to the examples and it does not work) here is the full code:
Code: Select all
public class Main extends Game {

   public AssetManager assetManager;

   private static SpriteBatch batch;
   private static OrthographicCamera camera;
   private static float WEIGHT;
   private static float HEIGHT;
   private GameStateManager gsm;

   @Override
   public void create () {
      assetManager = new AssetManager();
      WEIGHT  = 320;
      HEIGHT = 480;
      batch = new SpriteBatch();
      camera = new OrthographicCamera();
      gsm = new GameStateManager(this);
      setScreen(new LoadingView(this));
   }
   @Override
   public void render () {
      super.render();
   }
   @Override
   public void dispose () {

   }

   public GameStateManager getGsm() {
      return gsm;
   }
   public SpriteBatch getSpriteBatch(){
      return batch;
   }
   public OrthographicCamera getCamera(){
      return camera;
   }
   public float getWeight(){
      return WEIGHT;
   }
   public float getHeight(){
      return HEIGHT;
   }
}

Code: Select all
public class LoadingView implements Screen {

    private Main app;
    private ShapeRenderer shapeRenderer;


    public LoadingView(final Main app){
        this.app = app;
        shapeRenderer = new ShapeRenderer();

        queueAssets();
    }


    private void update(float delta){
        if (app.assetManager.update()){
            app.setScreen(new MenuView(app.getGsm()));
        }
    }

    private void queueAssets() {
        app.assetManager.load("textures/back.png", Texture.class);
        app.assetManager.load("skin/skin/uiskin.json", Skin.class);
    }

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        update(delta);
    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}

Code: Select all
public class GameView extends GameState implements Screen{

    private float CAMERA_WIDTH;
    private float CAMERA_HEIGHT;
    private float ASPECT_RATIO;
    private Viewport viewPort;

    private Skin skin;
    private Stage stage;
    private Texture background;

    //GRID
    private int boardSize = 4;
    private int holeX, holeY;
    private SlideButton [][] buttonGrid;

    //NAVIGATIONS
    private TextButton backButton;

    //Label
    private Label labelInfo;

    public GameView(GameStateManager gsm) {
        super(gsm);
        CAMERA_WIDTH = game.getWeight();
        CAMERA_HEIGHT = game.getHeight();
        ASPECT_RATIO = gsm.getWeight() / gsm.getHeight();
        viewPort = new FillViewport(CAMERA_WIDTH,CAMERA_WIDTH/ASPECT_RATIO);
        this.camera.setToOrtho(true, CAMERA_WIDTH, CAMERA_WIDTH / ASPECT_RATIO);
        this.camera.position.set(new Vector3(CAMERA_WIDTH / 2f, (CAMERA_WIDTH / ASPECT_RATIO) / 2f, 0));

        background = game.assetManager.get("textures/back.png", Texture.class);
        skin = game.assetManager.get("skin/skin/uiskin.json", Skin.class);
    }

    @Override
    public void show() {
        stage = new Stage(viewPort);
        Gdx.input.setInputProcessor(stage);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(background, 0,0);
        batch.end();

        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {
        viewPort.update(width, height,true);
    }
    @Override
    public void pause() {

    }
    @Override
    public void resume() {

    }
    @Override
    public void hide() {

    }
    @Override
    public void dispose(){
        stage.dispose();
    }

TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: AssetsManager [No loader for type: TextureRegion]

Postby TruePlayer » Thu Sep 12, 2019 10:32 pm

THE PROBLEM IS SOLVED))) I just forgot that my GameStateManager creates classes before loading the textures into them. I'm a fool in general)
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest