1
\$\begingroup\$

In the following code segment, the click event for image element is not registered. However, if i comment out stack.add(shapeLabel) statement, then the image button is able to register the click event. Why is it so ?

        private Array<Shape> tableShapes;
        private Array<Stack> tableofStackedShapes;
        ....
        ....
        Stack stack = new Stack();
        Label shapeLabel;
        colorIndex = MathUtils.random(colorsList.size - 1);
        cellShape = shapesList.get(MathUtils.random(shapesList.size - 1));
        String filename = cellShape + "/" + cellShape + "_" + colorsList.get(colorIndex) + ".png";
        img = new Shape(cellShape, colorsList.get(colorIndex), new Texture(filename)); 

        if (this.currentLevel > 2) {
            int randomNumber = MathUtils.random(0, 9);
            img = new Shape(cellShape, colorsList.get(colorIndex), null, randomNumber, new Texture(filename)); 
            img.setSize(cellSize * ((float)stage.getWidth() / stage.getHeight()), cellSize);
            stack.add(img);
            shapeLabel = new Label("" + randomNumber, new LabelStyle(new BitmapFont(), com.badlogic.gdx.graphics.Color.BLACK));
            shapeLabel.setAlignment(Align.center);
            shapeLabel.setBounds(img.getImageX(), img.getImageY(), img.getWidth(), img.getHeight());
            stack.add(shapeLabel);
        }   else {
            img = new Shape(cellShape, colorsList.get(colorIndex), new Texture(filename)); 
            img.setSize(cellSize * ((float)stage.getWidth() / stage.getHeight()), cellSize);
            stack.add(img);
        }
        stack.debugAll();
        tableofStackedShapes.add(stack);
        tableShapes.add(img); 
    }

My suspicion is on chaining of events, and that the label is restricting the click events to be detected by the img element. But I don't know what exactly is triggering this and how to fix it. Thanks for any inputs .

\$\endgroup\$
0
\$\begingroup\$

The answer lies in here : shapeLabel.setTouchable(Touchable.disabled);

With this I am able to achieve what I intended to do. The other alternative I found is to relay the events using InputMultiplexer. But, I felt the above solution to be simplest.

\$\endgroup\$

You must log in to answer this question.

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