2013-10-09 115 views
0

我有一個代碼在俄羅斯方塊遊戲中旋轉一塊,但我不知道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

很難通過閱讀片段只是告訴,但在我看來,xOffsetyOffset值指的是旋轉的中心點。