Question

Okay so I'm starting out with libgdx and starting by following a couple of tutorials ... first couple i did went of without a hitch however I am now attempting to follow a slightly more complex one on javacodegeeks.com here, and although it's a little dated through google and my own knowledge I've been able to resolve issues until now ... basically I am attempting to load a Texture on a rectangle here is the most relavent code

public WorldRenderer(World world, boolean debug) {
      this.world = world;
      this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
      this.cam.position.set(CAMERA_WIDTH / 2f, CAMERA_HEIGHT / 2f, 0);
      this.cam.update();
      this.debug = debug;
      spriteBatch = new SpriteBatch();
      loadTextures();
}

 private void loadTextures() {
      bobTexture = new  Texture(Gdx.files.internal("bob_01.png"));
      blockTexture = new Texture(Gdx.files.internal("block.png"));
     }
 public void render() {
      spriteBatch.begin();
       drawBlocks();
       drawBob();
      spriteBatch.end();
      if (debug)
       drawDebug();
     }
 private void drawBob() {
      Bob bob = world.getBob();
      spriteBatch.draw(bobTexture, bob.position.x * ppuX, bob.position.y * ppuY, Bob.SIZE * ppuX, Bob.SIZE * ppuY);
     }

 private void drawBlocks() {
      for (Block block : world.getBlocks()) {
       spriteBatch.draw(blockTexture, block.getPosition().x * ppuX, block.getPosition().y * ppuY, Block.SIZE * ppuX, Block.SIZE * ppuY);
      }
     }

now when attempting to run the project on both android and desktop I have recieved the same sort of error when attempting to load the internal file block_01.png

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: block.png
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
    at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
    at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
    at wiser.development.starAssault.view.WorldRenderer.loadTextures(WorldRenderer.java:58)
    at wiser.development.starAssault.view.WorldRenderer.<init>(WorldRenderer.java:53)
    at wiser.development.starAssault.screens.GameScreen.resize(GameScreen.java:27)
    at com.badlogic.gdx.Game.setScreen(Game.java:62)
    at wiser.development.starAssault.StarAssault.create(StarAssault.java:11)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: java.io.IOException: couldn't load pixmap 8bit only
    at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:57)
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:138)

now line 58 of WorldRenderer is this bobTexture = new Texture(Gdx.files.internal("bob_01.png"));

.. some important things to note: 1) I am using the most up to date stable version of libgdx ... installed a few days ago

2) libgdx uses gradle to build project (something I honestly don't understand) however I know that part of the buuild process is link the folder in starAssault-android/asset for all images, sounds, etc.

3) this source linking was originally broken when I checked, however i rebuilt it following the steps in manual set-up , refreshed, and cleaned project still getting the same error

4) block.png is most certainly in starAssault-android/assets and is also a 32px*32px image (docs say must be power of 2 ... which this is))

5) There is no report issues on the github page for the project and I believe I am properly using the spritbatch.draw function aswell as importing of the texture as referenced in docs here

Anyway's I have absolutely no idea why this is not working now, and am hoping someone here can help me out, or point me in the right direction

EDIT

this is debug mode... asked on someone on libgdx irc channel

 private void drawDebug() {
  // render blocks
  debugRenderer.setProjectionMatrix(cam.combined);
  debugRenderer.begin(ShapeType.Line);
  for (Block block : world.getBlocks()) {
   Rectangle rect = block.getBounds();
   float x1 = block.getPosition().x + rect.x;
   float y1 = block.getPosition().y + rect.y;
   debugRenderer.setColor(new Color(1, 0, 0, 1));
   debugRenderer.rect(x1, y1, rect.width, rect.height);
  }
Was it helpful?

Solution

forgot to post the answer to the question, It was indeed the specific image , apparently there is some reason that libgdx can't load an 8-bit pixmap as indicated by this line here in the stack trace at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114) Caused by: java.io.IOException: couldn't load pixmap 8bit only

. I am not sure as to the exact reason why this does not work (understanding of images codecs not that in depth). However, the issue was made aware to me over on the freenode irc channel for the libgdx community #libgdx . By a member mobidevlop, highly recomend using this resource the channel was very helpful!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top