2

disclaimer: I'm new to LibGDX and have a rather basic understanding of java. I used Google and Stackoverflow already for searching for an answer, but no avail. Sorry for english, I'm not a native speaker.

Here's my question:

I want to create a number of buttons for a game, and in order to save code I'm trying to create a custom TextButton class. However, I'm running into issues.

Here's my code so far:

package com.mygame.game;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
public class customButton extends TextButton{
 TextButtonStyle customButtonStyle;
 BitmapFont font;
 TextureAtlas buttonAtlas;
 public customButton(String text, Skin skin, int x, int y) {
 super(text, skin);
 customButtonStyle = new TextButtonStyle();
 customButtonStyle.font = font;
 customButtonStyle.up = skin.getDrawable("accept-button");
 this.setStyle(customButtonStyle);
 this.setPosition(x, y);
 }
}

I'm calling this with this code:

customButton testlol;
...
skin = new Skin();
buttonAtlas = new TextureAtlas(Gdx.files.internal("icons"));
skin.addRegions(buttonAtlas);
testlol = new customButton("Testhallo", skin, 200, 200);
stage.addActor(testlol);

and so on. However, I'm getting an error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: No com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle registered with name: default

...

at com.mygame.game.customButton.<init>(customButton.java:17)

The error is referencing to this line:

 super(text, skin);

(I removed some redundant error text)

I cannot see what is basicly wrong. What is my (fundamental error here? : /

asked May 25, 2015 at 20:44

1 Answer 1

2

The super constructor you're calling super(text, skin); tries to instantiate the TextButton with a default style. So your skin must have a default style already defined for TextButtons. Or you can copy and paste the code from the super class's constructor instead of calling it, and adapt it as needed to skip trying to apply a default style.

answered May 25, 2015 at 21:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.