嘿,我正试图围绕它的中心旋转一个矩形,当我尝试旋转矩形时,它同时向上移动并向左移动。有没有人有任何想法如何解决这个问题?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