0
我正在製作一個遊戲,在該遊戲中,我必須在n×n個網格上移動小方格,並且它們必須平滑過渡。這是我所做的交換方法,它應該能夠在屏幕上繪製我的過渡,但由於某種原因,它並沒有這樣做。我在一個簡單的項目上嘗試了一個更簡單的代碼版本,來回移動一個Square,它的功能就像一個魅力,所以我不確定爲什麼這不會重新繪製。這只是我的代碼中的一部分,所以如果對我的代碼有任何其他疑問,請去詢問。Java中的repaint()方法在翻譯後不會重新繪製我的Rectangle
在此先感謝。 (:
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;
}