嘿,我正試圖圍繞它的中心旋轉一個矩形,當我嘗試旋轉矩形時,它同時向上移動並向左移動。有沒有人有任何想法如何解決這個問題?Python中的矩形旋轉/ Pygame
def rotatePoint(self, angle, point, origin):
sinT = sin(radians(angle))
cosT = cos(radians(angle))
return (origin[0] + (cosT * (point[0] - origin[0]) - sinT * (point[1] - origin[1])),
origin[1] + (sinT * (point[0] - origin[0]) + cosT * (point[1] - origin[1])))
def rotateRect(self, degrees):
center = (self.collideRect.centerx, self.collideRect.centery)
self.collideRect.topleft = self.rotatePoint(degrees, self.collideRect.topleft, center)
self.collideRect.topright = self.rotatePoint(degrees, self.collideRect.topright, center)
self.collideRect.bottomleft = self.rotatePoint(degrees, self.collideRect.bottomleft, center)
self.collideRect.bottomright = self.rotatePoint(degrees, self.collideRect.bottomright, center)
所以你的意思是,如果我要檢查,看是否有在矩形內的碰撞,我不得不做出的一個副本矩形,然後每次從副本旋轉它?對不起,我只是很難理解這一點。 – mramazingguy
對於任何未來碰到過這個問題的人......他說的是Pygame的引擎不理解旋轉的矩形。除了常規的未旋轉矩形之外,您無法對其進行碰撞檢測。 – atomictom