LibGDX - Missing LabelStyle font error - libgdx

I have a folder named UI and inside it, it contains a button.pack and a button.png (I created this with the GDX texture packer). Here is the line of code for the .pack.
atlas = new TextureAtlas(Gdx.files.internal("ui/button.pack"));
skin = new Skin(atlas);
But when I run the application it gives me this error:
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Missing LabelStyle font.
Am I doing something wrong? What is the excact problem?

Related

Do I have to always have an .atlas file when making a skin?

I'm currently trying to build a simple loading screen for my game and am trying to get a skin for a font.
When I try to get the the skin though, with skin = game.manager.get("bin/ui/loading.json", Skin.class);, this error occurs:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: File not found: bin\ui\loadingSkin.atlas (Internal)
at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:540)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:356)
at com.badlogic.gdx.assets.AssetManager.finishLoading(AssetManager.java:377)
at com.Sidescroll.game.LoadingScreen.show(LoadingScreen.java:32)
at com.badlogic.gdx.Game.setScreen(Game.java:61)
at com.Sidescroll.game.Sidescroll.create(Sidescroll.java:20)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: bin\ui\loadingSkin.atlas (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:58)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:34)
at com.badlogic.gdx.assets.AssetLoadingTask.handleSyncLoader(AssetLoadingTask.java:98)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:87)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:477)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:354)
... 6 more
In my current assets/ui folder are 5 files:
loading_0.png - BitmapFont image
loading.fnt - Font file
loading.pack - used TexturePacker to pack the single image
loading.png - TexturePacker image
loadingSkin.json - Skin.json, where BitmapFont and LabelStyle is described
The part where Im trying to use assetmanager:
//this is the beginning of the show method of my loadingScreen, nothing
//happened before
game.manager.load("bin/ui/loading.pack", TextureAtlas.class);
game.manager.finishLoading();
atlas = game.manager.get("bin/ui/loading.pack");
// do i need an atlas here ?
game.manager.load("bin/ui/loadingSkin.json", Skin.class);
game.manager.finishLoading();
skin = game.manager.get("bin/ui/loading.json", Skin.class);
Question is, do I always need an atlas? if yes, how do I create one, if not, why does the error occur?
EDIT: I'm using release 1.5.4 of libgdx and do not have android in my project
the Skin has many various contructors like:
Skin()
Skin(FileHandle skinFile)
Skin(FileHandle skinFile, TextureAtlas atlas)
Skin(TextureAtlas atlas)
If you are using the JSON version of constructor you are just passing the json configuration file to it. Skin needs to have some texture atlas so with this option by default it is looking for the .atlas file named exatcly like json file. It means that when you are using file name loadingSkin.json:
game.manager.load("bin/ui/loadingSkin.json", Skin.class);
it will look for the loadingSkin.atlas file and because there is nothing like this it causes the error.
Now you have two option:
create file named like your json but with atlas extension (.atlas is exactly like .pack - you can just change extension or create a file with .atlas instead of .pack in TexturePacker)
loading.pack -> loading.atlas
When changing names be aware of you texture .png file! (The .pack/.atlas file has its name inside - check with editor)
use another constructor of skin like:
Skin(FileHandle skinFile, TextureAtlas atlas)
You are passing filehandle to .json and TextureAtlas instance of the skin texture
TextureAtlas atlas = game.manager.get("bin/ui/loading.pack", TextureAtlas.class);
Skin skin = new Skin( Gdx.files.internal("bin/ui/loadingSkin.json"), atlas);
This line causes the error:
game.manager.load("bin/ui/loadingSkin.json", Skin.class);
When I looked into SkinLoader class' source I've seen that it loads the file by appending .atlas by default:
#Override
public Skin loadSync (AssetManager manager, String fileName, FileHandle file, SkinParameter parameter) {
String textureAtlasPath = file.pathWithoutExtension() + ".atlas";
...
So it seems like you need a TextureAtlas for your skin. You can create TextureAtlas by using https://libgdx-texturepacker-gui.googlecode.com/files/gdx-texturepacker-3.2.0.zip
You can create a TextureAtlas named loadingSkin.atlas and put it under bin\ui\loadingSkin.atlas. If you want to create an atlas with another name and tell the loader which TextureAtlas to use, you can pass SkinParameter to your load method:
SkinLoader.SkinParameter loadingSkinParameter = new SkinLoader.SkinParameter();
loadingSkinParameter.textureAtlasPath = "YOUR_TEXTURE_ATLAS_PATH";
game.manager.load("bin/ui/loadingSkin.json", Skin.class, loadingSkinParameter);

how to resolve stringIndexOutofBoundsException when bitmap is initialized

I am learning to develop a game using libgdix.I follow the book Learning LibGDX game development,second edition.
I am getting stuck on using Bitmapfont.
public class AssetsFonts
{
public final BitmapFont defaultSmall;
public final BitmapFont defaultNormal;
public final BitmapFont defaultBig;
public AssetsFonts()
{
defaultSmall = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultNormal = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultBig = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultSmall.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultNormal.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultBig.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear);
}
}
when i run this am getting the following error
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: images/arial-15.fnt
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:650)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.<init>(BitmapFont.java:465)
at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:115)
at com.packtpub.libgdx.canyonbunny.game.Assets$AssetsFonts.<init>(Assets.java:125)
at com.packtpub.libgdx.canyonbunny.game.Assets.init(Assets.java:49)
at com.packtpub.libgdx.canyonbunny.CanyonBunnyMain.create(CanyonBunnyMain.java:22)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(String.java:1918)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:476)
... 7 more
The exception you've got is this one. Practically saying that something went wrong while loading the file. The inner exception shows what went wrong while loading:
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(String.java:1918)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:476)
Since there's no call to String#substring at line 476, this is an indication that you're using an older version of libgdx (which is to be expected, because a lot has changed to that file recently). So I'd suggest that you update to the latest nightly (or check the github history at the time of the version you're using), so you know which call is actually causing the error.
Either way, the fact that a substring call failed while loading your file is a good indication that the file is likely to be corrupt or doesnt meet the expected format in another way. Assuming you want to use the font that the libgdx tests uses, then you can download the correct version here and the required image here. Make sure to place the image in the same folder as the fnt file.
Your real problem is that it can't find the font file...
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: images/arial-15.fnt
Make sure the file is in the correct place, which is probably android/assets/images but depends on your project setup.
Also ensure that your run the desktop version with android/assets as the working folder.

Physics Body Editor error

I get this error when trying to initialize BodyEditorLoader from this library http://www.aurelienribon.com/blog/projects/physics-body-editor/
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:127)
Caused by: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape(Native Method)
at com.badlogic.gdx.physics.box2d.PolygonShape.<init>(PolygonShape.java:29)
at aurelienribon.bodyeditor.BodyEditorLoader.<init>(BodyEditorLoader.java:31)
How can i fix it?
to see the code where it is called, but I venture to say that the problem is the call to your world this must be called before here's an example:
This a example compile good:
oWorld = new World(gravedad, dormir);
loader = new BodyEditorLoaderNewW(
Gdx.files.internal("data/test.json"));
This a example not compile good:
loader = new BodyEditorLoaderNewW(
Gdx.files.internal("data/test.json"));
oWorld = new World(gravedad, dormir);
recive this:
java.lang.UnsatisfiedLinkError:
com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape () J
note the difference in the world is called one after so gives:
it is possible that in the future can, need this:
BodyEditorLoader - noSuchMethod
but if this is not the solution you could put some of the code, I hope you help
Based on this https://github.com/libgdx/libgdx/issues/2393 the problem is because natives aren't loaded before creating shape.
There are two solutions:
First is creating World instance before creating any shapes.
Second is calling Box2D.init(); before creating any shapes. This method is preferred because you don't need to create World instance and it's much more obvious.
Use this version https://gist.github.com/grulg/8691e7ee7709367ce165 instead of version from Google Code.

Having an issue loading resource from assetmanager

I am using assetmanager to laod a .pack file
//load assetmanager textures
Manager.load("Pong.pack", TextureAtlas.class); << line 34
Manager.finishLoading();
TextureAtlas atlas = Manager.get("Pong.pack");
the line with this << is the culprit from the log
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.Shadow.Pong.Game.Assets.init(Assets.java:34)
I pointed the working directory to the resource folder for the desktop module. So i dont know why it keeps saying nullpointerexception.
thanks in advance
try this
TextureAtlas atlas = Manager.get("Pong.pack", TextureAtlas.class);
having a wild guess because many information are missing.
I mean what exactly in Asset.java line 34.
Manager instantiated or not and many other things.
But i guess one i suggested seems to be the problem
I Realized that i didint call a new assetmanager for the parameter for the asstmanager call so thats why it was giving the nullpointer

Starling is giving Unable to transcode Image Error

I am working on a prototype in which I'm adding a texture to movieClip.
Here is my code :
[Embed(source = "/../assets/demo_img.png")]
protected var asset01:Class;
[Embed(source="/../assets/demo_img.xml",mimeType="application/octet-stream")]
protected var data01:Class;
and my movieClip code is :
var myTexture:Texture = Texture.fromBitmap(new asset01());
var atlas:TextureAtlas = new TextureAtlas(myTexture, XML(new data01()));
var mc:MovieClip = new MovieClip(atlas.getTextures("demo_img_"), 10);
but it gives me error :
Error: exception during transcoding: Failed to grab pixels for image \..\PP143Starling\assets\demo_img.png
If anyone have any idea about it, please share.
I faced similar issue and the weird part was it started coming without any change in the code. Initially i faced an issue with windows memory and then eclipse memory and then this error surfaced:
exception during transcoding failed to grab pixels for image
Embed was also not recognized by compiler anymore.
The fix is very simple. I just cleaned my project in eclipse and the error was cleared.