I have been working for several days to try and figure out how to change a texture whenever a scene2d Table is clicked in libgdx, I am using pixmaps to dynamically change the textures colors instead of changing the texture completely.

everything works fine when i detect key presses so whenever i press 1 the color of the players hair changes to a random color but now i want it to happen when i press a Table.

to change the texture i use this method

public static Texture genDynamicTexture(String path, HashMap<String,Color> colors) {

    //load texture from asset handler
    Texture texture = GameUtils.getGame().manager.get(path,Texture.class);

    //create pixmap from texture
    if(!texture.getTextureData().isPrepared()) {
    //transfer pixel data from gpu to cpu
    Pixmap pixmap = texture.getTextureData().consumePixmap();

    //grey-scale colors
    Color gsHair = toColor(207,31,201);
    Color gsSkin = toColor(207,97,31);
    Color gsShirt1 = toColor(39,207,31);
    Color gsShirt2 = toColor(65,65,160);
    Color gsPants = toColor(90,9,22);
    Color gsShoe1 = toColor(253,255,66);
    Color gsShoe2 = toColor(43,58,50);
    Color black = toColor(0,0,0);

    //loop through pixels in the pixmap
    for(int x = 0; x < pixmap.getWidth(); x++) {
        for(int y = 0; y < pixmap.getHeight(); y++) {
            int pixelColor = pixmap.getPixel(x, y);
            if(pixelColor != 0 && pixelColor != Color.rgba8888(black)) {
                if(pixelColor == Color.rgba8888(gsHair)) {
                    pixmap.drawPixel(x, y);
                }else if(pixelColor == Color.rgba8888(gsSkin)) {
                    pixmap.drawPixel(x, y);
                }else if(pixelColor == Color.rgba8888(gsShirt1)) {
                    pixmap.drawPixel(x, y);
                }else if(pixelColor == Color.rgba8888(gsShirt2)) {
                    pixmap.drawPixel(x, y);
                }else if(pixelColor == Color.rgba8888(gsPants)) {
                    pixmap.drawPixel(x, y);
                }else if(pixelColor == Color.rgba8888(gsShoe1)) {
                    pixmap.drawPixel(x, y);
                }else if(pixelColor == Color.rgba8888(gsShoe2)) {
                    pixmap.drawPixel(x, y);

    //transfer pixel data from cpu to gpu
    Texture tex = new Texture(pixmap);
    return tex;


like i said everything works fine if it is a key press but when i detect it using a Table it does not work ( i have already added it to the stage and am calling stage.act() and stage.draw() )

color.addListener(new ClickListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return true;
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            characterPack.reloadSpriteSheet("Players/greyscale-player.png", 2, 2, characterPack.colors, "skin");

thanks in advance.


1 Answer 1


I solved my problem by resetting what frame of the texture region was being rendered so in my code it was

characterPack.skin = characterPack.frames[0];

another option i found was i had my direction set to UNUSED so once i set it to down it updated itself.

the result reloads the colors to change the textures colors based on what options the user clicks.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .