Right now I am working on a UI for my game. I'm adding my own UI elements to a group and adding that to a stage. But the listeners I'm adding to the actors are not firing off at all. I have looked on some StackExchange posts for answers but I couldn't find a good answer to my problem.
Right now the logic flow is Stage <-- Group <-- Custom Actors(FurnaceUI & FurnaceRecipeUI)
.
This is the HUD class (hastebin since it wouldnt paste right): https://hastebin.com/zelibejopa.java
FurnaceUI:
public class FurnaceUI extends Actor {
private final Texture uiBackground;
public FurnaceUI(Group group, float x, float y, float width, float height){
group.addActor(this);
this.setX(x);
this.setY(y);
this.setWidth(width);
this.setHeight(height);
this.uiBackground = new Texture(Gdx.files.internal("ui/furnaceui.png"));
for(FurnaceRecipe recipe : FurnaceRecipeRegistry.getRecipes()){
group.addActor(new FurnaceRecipeUI(recipe, this.getX() + 10, this.getY() + 490, 280, 100));
}
setBounds(x,y, width, height);
setTouchable(Touchable.enabled);
addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("usjkmd");
return super.touchDown(event, x, y, pointer, button);
}
});
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
batch.draw(uiBackground, this.getX(), this.getY(), this.getWidth(), this.getHeight());
}
FurnaceRecipeUI:
public class FurnaceRecipeUI extends Actor {
private final FurnaceRecipe recipe;
private final static Texture texture = new Texture(Gdx.files.internal("ui/furnace_recipe_ui.png"));
private final static Texture arrowTexture = new Texture(Gdx.files.internal("ui/ui_arrow.png"));
int i = 0;
public FurnaceRecipeUI(FurnaceRecipe recipe, float x, float y, float width, float height){
this.recipe = recipe;
this.setX(x);
this.setY(y);
this.setWidth(width);
this.setHeight(height);
setBounds(x,y, width, height);
setTouchable(Touchable.enabled);
addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("aight");
return super.touchDown(event, x, y, pointer, button);
}
@Override
public boolean keyDown(InputEvent event, int keycode) {
System.out.println(keycode);
return true;
}
});
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
batch.draw(texture, this.getX(), this.getY(), this.getWidth(), this.getHeight());
for(Map.Entry<Item, Integer> result : recipe.getIngredients().entrySet()){
batch.draw(result.getKey().getTexture(), this.getX() + 10 + (i * 58), this.getY() + 20, 64, 64);
i++;
}
i = 0;
batch.draw(arrowTexture, this.getX() + 110, this.getY() + 40, 64, 32);
batch.draw(recipe.getOutput().getTexture(), this.getX() + 200, this.getY() + 20, 64, 64);
}}
Then here is the main class of my game with the input multiplexer: https://hastebin.com/donosavoru.java