So I am trying to create a simple match 3 game. I created an actor class Tile to store the image and data about row and column and created another class GameField that has an array of size 9 * 9 of tile.
I created an function named swap tiles to swap the tiles which is as follow but it has an strange behaviour that after any two tiles have been swapped one of them responds to clicks whereas the other one stops responding to the clicks further.
Here are the input listener of Tile class and the swap tile function of gamefield:
addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
setActiveSprite(row, column, colour);
System.out.println("clicked" + "row :" + row + "column" + column);
return false;
}
});
public void setActiveSprite(int r, int c, int colour){
System.out.print(colour);
if (!(gf.activeTile.colour==0)){
gf.swapTiles(r, c, colour);
gf.activeTile.colour=0;
} else {
gf.activeTile.setAll(r, c, colour);
}
}
public void swapTiles(int r, int c, int colour) {
gameField[activeTile.row][activeTile.column].addAction(Actions.moveTo(
(40 + ((gameField[r][c].getHeight() * c) + (10 * c))),
(200 + (gameField[r][c].getWidth() * r)),
0.5f));
//setting the new position of clicked tile
gameField[r][c].addAction((Actions.moveTo(
(40 + ((gameField[r][c].getHeight() * activeTile.column) + (10 * activeTile.column))),
(200 + (gameField[r][c].getWidth() * activeTile.row)),
0.5f)));
Tile Temp = gameField[activeTile.row][activeTile.column];
gameField[activeTile.row][activeTile.column] = gameField[r][c];
gameField[activeTile.row][activeTile.column].row = activeTile.row;
gameField[activeTile.row][activeTile.column].column = activeTile.column;
gameField[r][c] = Temp;
gameField[r][c].row = r;
gameField[r][c].column = c;
}
Please notify me the possible error which i think is there in the swapTile function