The weekly report of Android Game Untitled is paused, the game is still in progress.
TexturePacker is useful extension class of Libgdx, it packed all images in one folder to one image with power of 2 width and height and create a pack file record the coordinate info of each sub image. With TextureAtlas you can load subimage from the assembled one easily. Why we use this not directly use several images. That’s because
1.The width and height of Texture should be pow of 2, that’s not convenient when you want use other width and length.
2.Loading several images is slower than loading one.
When I use the TexturePacker I get an exception
Exception in thread “main” java.lang.ClassCastException: [B cannot be cast to [S
at sun.awt.image.ShortInterleavedRaster.getDataElements(ShortInterleavedRaster.java:245)
at com.matrix.libgdx.util.TexturePacker.squeeze(TexturePacker.java:362)
at com.matrix.libgdx.util.TexturePacker.addImage(TexturePacker.java:98)
at com.matrix.libgdx.util.TexturePacker.<init>(TexturePacker.java:78)
at com.matrix.libgdx.util.TexturePacker.process(TexturePacker.java:748)
at com.matrix.libgdx.util.TexturePacker.process(TexturePacker.java:837)
at com.matrix.libgdx.util.MyPacker.main(TexPacker.java:12)
Because I don’t find any others who confronted the same problem, I think it’s maybe my fault. After digging a while, using debug I found the reason, Every time when squeeze a special file the source.getAlphaRaster() return a ShortInterleavedRaster and that lead to the exception.
I have no idea of this png file, it’s same as others to me. And the only difference between them maybe the special one made by Photoshop and others by GIMP. It seems like the alpha raster of image made by Photoshop is short not byte. It’s just my guess, not sure about that. After removed it, everything is OK. 