0
\$\begingroup\$

I created two-dimensional array of Button actor, then I added new ClickListener() { touchDragged } as the following code:

buttons = new Button[3][3];

for (int row = 0; row < buttons.length; row++) {
    for (int col = 0; col < buttons[0].length; col++) {

buttons[row][col] = new Button(drawable);

buttons[row][col].addListener(new ClickListener() {

                @Override
                public void touchDragged(InputEvent event, float x, float y, int pointer) {
                    for (int row = 0; row < buttons.length; row++) {
                        for (int col = 0; col < buttons[0].length; col++) {
                            if (buttons[row][col].isOver()) {
                                buttons[row][col].setColor(Color.GREEN);
                            }
                        }
                    }
                }
   }
}

the code inside touchDragged method if the buttons isOver the buttons colored GREEN (it works fine) as shown in image enter image description here

Now, How can I remove Color.GREEN i.e. (Color.WHITE) from buttons in the same calling touchDragged method, I mean undo GREEN to WHITE ??

this image clear my question : enter image description here

like Alphapetty Game from king company, if you know it :).

Sorry, For bad English

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

1- Create List :

private List<Integer> list;

// In create OR show Method 
list = new ArrayList<Integer>();

2- Create this line code (as ID for buttons[row][col]):

buttons[row][col].setName("" + id++);

3- Write this code inside your touchDragged .. after your loop:

if (buttons[row][col].isOver()) {
    try {
        if (list.contains(Integer.parseInt(buttons[row][col].getName()))) {
            if(Integer.parseInt(buttons[row][col].getName()) == list.get(list.size() - 2)) {
                stage.getRoot().findActor("" + list.get(list.size() - 1)).setColor(Color.WHITE);
                list.remove(list.size() - 1);
            }
        } else {
            buttons[row][col].setColor(Color.GREEN);
            list.add(Integer.parseInt(buttons[row][col].getName()));
        }
      } catch (Exception e) {
           System.out.println(e.getClass());
      }
}

4- See the answer in this video

\$\endgroup\$

You must log in to answer this question.

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