我正在制作一个游戏,在这个游戏中,我必须在n×n格子上移动小方格,并且他们必须平稳过渡。这是我所做的交换方法,它应该能够在屏幕上绘制我的过渡,但由于某种原因,它并没有这样做。我在一个简单的项目上尝试了一个更简单的代码版本,来回移动一个Square,它的功能就像一个魅力,所以我不确定为什么这不会重新绘制。这只是我的代码中的一小部分,所以如果对我的代码有其他疑问,请去问。
提前致谢。 (:
public void swap( int y, int x ) {
long time = System.currentTimeMillis();
int counter = 0;
swapNum = tiles[y][x];
rect = (Rectangle) rectangles[y][x].clone();
while(counter < rect.height) {
if(System.currentTimeMillis() - time > 5) {
rect.translate(this.y-y, this.x-x);
time = System.currentTimeMillis();
counter++;
repaint();
}
}
swapNum = 0;
rect = new Rectangle();
int temporary = tiles[this.y][this.x];
tiles[this.y][this.x] = tiles[y][x];
tiles[y][x] = temporary;
this.x = x;
this.y = y;
}