I have an image and I want to make clickable this image. I have already done this a lot of times, but this time doesn't work. Probably because the image is from a class which extends Image:
public class BitmapFontGenerale extends Image
{
BitmapFont bitmapFont;
String scritta;
private float x;
private float y;
public BitmapFontGenerale(BitmapFont bitmapFont1, String string, float scale)
{
bitmapFont = bitmapFont1;
bitmapFont.setColor(Color.BLACK);
bitmapFont.getData().setScale(scale);
scritta = string;
}
@Override
public void draw(Batch batch, float parentAlpha)
{
bitmapFont.draw(batch,scritta,x,y);
}
public void setX(float x)
{
this.x = x;
}
public void setY(float y)
{
this.y = y;
}
public float getX()
{
return x;
}
public float getY()
{
return y;
}
}
This is the code which I used to set the input:
image.addListener(new ClickListener()
{
@Override
public void clicked (InputEvent event, float x, float y)
{
Gdx.app.log("CLICKED ", "CLICKED");
}
});
stage.add(image);
Gdx.input.setInputProcessor(stage);
This code works if image is from Image class and not if it's from a class which extends Image. Note: I need to extend Image class. What's the problem?
Gdx.input.getInputProcessor() == stage
to see if your stage is your actual input processor. \$\endgroup\$ – Charanor Jul 8 '17 at 12:55Label
actor. Also since stage isn't your input processor your problem is 99% that you're using another input processor that overrides the stage one. \$\endgroup\$ – Charanor Jul 8 '17 at 13:05Gdx.input.setInputProcessor(stage);
thenGdx.input.setInputProcessor(somethingElse);
your stage won't register input. You can only have one input processor at a time. If you want multiple you need to use anInputMultiplexer
. \$\endgroup\$ – Charanor Jul 8 '17 at 13:09