[英]Why does my GUI window freeze whenever ActionListener is performed?
[英]Why does this graphics loop freeze my gui?
所以在我看来,这段代码看起来不错,但我不能真正说出它的好之处,因为它冻结了整个绘画循环。 在没有所有抵消麻烦之前,它工作得很好。
int offsetX = 0;
int offsetY = 0;
for(int y = 0, canvasY = offsetY + y, x = 0, canvasX = offsetX + x; canvasY < mapHeight + offsetY && canvasX < mapWidth + offsetX; y++, x++) {
int tileToPaint = canvasX + (canvasY * mapWidth);
tileObject = getObject(tileToPaint);
int locationX = tileSize * x;
int locationY = tileSize * y;
draw(tileObject, locationX, locationY);
}
问题在于它是无限的。
您的情况:
canvasY < mapHeight + offsetY && canvasX < mapWidth + offsetX
由于这些值都不会改变,因此永远为假。
我相信您想要做的是在draw
之后调用这些。
canvasY = offsetY + y;
canvasX = offsetX + x;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.