【发布时间】:2012-03-28 13:08:08
【问题描述】:
我正在制作一个游戏,我必须在 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;
}
【问题讨论】:
标签: java components repaint