Hello, I'm doing a game "Find a couple of numbers." Starring RecyclerView with GridLayoutManager . A field of 6 * 6 chips. I use my model for each item. In the game, I manage the chip states and update the RecyclerView using notifyItemChanged() . Disabled the animations built into the library so as not to interfere. Here is my class for chips
public class Chip { public static final int CHIP_HIDE = 0; public static final int CHIP_OPEN = 1; public static final int CHIP_CLOSED = 2; public static final int CHIP_UP = 3; public static final int CHIP_NO = 4; int number, drawable, textColor, state, offset; int[] drawables = {R.drawable.bg1, R.drawable.bg2, R.drawable.bg3, R.drawable.bg4}; int[] colors = {Color.WHITE, Color.WHITE, Color.BLACK, Color.WHITE}; Chip(int number){ this.number = number; this.drawable = drawables[number - 1]; this.textColor = colors[number - 1]; this.state = CHIP_NO; } int getNumber(){ return number; } int getDrawable(){ return drawable; } int getTextColor(){ return textColor; } int getState(){ return state; } int getOffset(){ return offset; } void setOffset(int offset){ this.offset = offset; } void setState(int state){ this.state = state; } } The chip consists of numbers. That is what I pass to the constructor. Depending on this number, the background is created in the model (there are 4 of them) and the text color. When you create a chip, it is given the status CHIP_NO . I also implemented getter methods and with them in the adapter I create the playing field.
When I open a chip, I change the state to CHIP_OPEN , when I close CHIP_CLOSED , when I delete CHIP_HIDE .
I decided to add a "ladder" animation before starting the game (like dots on the pattern lock screen. First, the upper left chip appears, then the one to the right and below, and so on until the lower right chip). For this, I created another state CHIP_UP and a two-dimensional array (matrix 11 * 6). This is how I cycle through the array and change the states of the chips.
(new Thread(new Runnable(){ @Override public void run() { try { for(int x = 0; x<ar.length; x++){ for(int y = 0; y<ar[x].length; y++){ list.get(ar[x][y]).setState(Chip.CHIP_UP); list.get(ar[x][y]).setOffset(x*1000); Message msg = h.obtainMessage(UPDATE, ar[x][y],0); h.sendMessage(msg); Log.d(LOG_TAG, "["+x+"]["+y+"] = " + ar[x][y]); } } } catch (Exception e) { Log.d(LOG_TAG, e.toString()); } } })).start(); Depending on x I throw a delay in the model class before the animation starts, so that all the chips are not animated at the same time. In the adapte, I set the animations to offset and run. But chips all the same appear all together. What's wrong?(
This is the order in which chips appear.
1 2,7 3,8,13 4,9,14,19 5,10,15,20,25 6,11,16,21,26,31 12,17,22,27,32 18,23,28,33 24,29,34 30,35 36