나는 비주얼드와 비슷한 게임을하고 있고, 얼마 동안은 응용 프로그램을 실행 한 후에 블록이 시각적으로 정확한 장소에 정확하게 위치하지는 않지만 논리적으로는 올바른 곳에서. 상황은 아래 그림과 같습니다.JavaFX 트랜지션 애니메이션이 그리드 패널의 아이들을 올바른 위치에 놓지 못함
나는 버그의 원인을 알 수 없습니다.
여기에는 지우고 내리는 방법에 대한 코드가 있습니다. 논리적으로는 이러한 방법이 유용합니다.
public void erase()
{
for (int i = 0; i < BlockManager.length; i++)
{
Block block = BlockManager.blocks[BlockManager.erased[i][0]][BlockManager.erased[i][1]];
BlockManager.blocks[BlockManager.erased[i][0]][BlockManager.erased[i][1]] = null;
FadeTransition transition = new FadeTransition(Duration.seconds(1), block);
transition.setFromValue(1);
transition.setToValue(0);
transition.setOnFinished(e ->
{
blockGridPan.getChildren().remove(block);
descend();
BlockManager.resetArrays();
});
transition.play();
}
}
int[][] descend = new int[HEIGHT * WIDE][2];
int descendLength = 0;
public void descend()
{
int[] columnX = new int[10];
int[] theUpperOne = new int[10];
Arrays.fill(theUpperOne, 10);
Arrays.fill(columnX, 0);
for (int j = 0; j < BlockManager.length; j++)
{
columnX[BlockManager.erased[j][0]]++;
if (BlockManager.erased[j][1] < theUpperOne[BlockManager.erased[j][0]])
{
theUpperOne[BlockManager.erased[j][0]] = BlockManager.erased[j][1];
}
}
TranslateTransition transition = null;
for (int i = 0; i < 10; i++)
{
if (columnX[i] == 0)
continue;
for (int j = WIDE - 1; j >= 0; j--)
{
if (BlockManager.blocks[i][j] == null)
continue;
int dY = 0;
for (int k = j + 1; k < WIDE; k++)
{
if (BlockManager.blocks[i][k] == null)
dY++;
}
if (dY != 0)
{
int deltaY = dY * 60;
transition = new TranslateTransition(Duration.seconds(1), BlockManager.blocks[i][j]);
transition.setByY(deltaY);
BlockManager.blocks[i][j + dY] = BlockManager.blocks[i][j];
BlockManager.blocks[i][j + dY].setPosition(i, j + dY);
BlockManager.blocks[i][j] = null;
BlockManager.blocks[i][j + dY].setDescended(true);
transition.play();
}
}
for (int j = columnX[i] - 1; j >= 0; j--)
{
int deltYJ = j * 60;
createOneBlock(i, j);
BlockManager.setBlockColorWithoutCheck(BlockManager.blocks[i][j]);
blockGridPane.add(BlockManager.blocks[i][j], i, 0);
System.out.println("show it");
BlockManager.blocks[i][j].setDescended(true);
transition = new TranslateTransition(Duration.seconds(1), BlockManager.blocks[i][j]);
transition.setByY(deltYJ);
transition.play();
}
}
if (transition != null)
transition.setOnFinished(e ->
{
BlockManager.resetArrays();
if (BlockManager.check())
erase();
});
}
}
내가 무슨 뜻인지 알 것 같지만 전환 후 자식 레이아웃을 변경하지 않기 위해 어떻게 그리드 패널을 만들 수 있습니까? 고맙습니다! –
문제가 성공적으로 해결되었습니다. 고맙습니다! –
@AndyLee 자신의 질문에 답하고 해결 방법을 다른 사람들과 정확히 공유 할 수 있다면 좋을 것입니다. 내가 한 일은 단순히 축소 및 탐색 할 수있는 방향을 제시하는 것입니다. :) – Jai