我有一个代码在俄罗斯方块游戏中旋转一块,但我不知道xOffset和yOffset变量的含义。你能为我解释一下吗?非常感谢!!
double xOffset = width / 2.0 - .5; double yOffset = height / 2.0 - .5;
//Create a new body
TPoint[] newBody = copyBody(body);
for(TPoint p : newBody){
//Rotoate 90 degrees counter clockwise about the origin
double newX = p.x;
double newY = p.y;
newX -= xOffset;
newY -= yOffset;
double temp = newX;
newX = -newY;
newY = temp;
newX += yOffset;
newY += xOffset;
p.x = (int) newX;
p.y = (int) newY;
}
return new Piece(newBody);
答案 0 :(得分:0)
通过阅读代码段很难说清楚,但在我看来,xOffset
和yOffset
值是指旋转的中心点。