【问题标题】:Center of Rotation, Pygame旋转中心,Pygame
【发布时间】:2015-04-14 23:30:34
【问题描述】:

我最近刚刚问了this 的问题。我得到了答案,唯一的问题是旋转很奇怪。它没有一个中心点。我可以描述旋转的最佳方式是将图像推到某个左侧的隐形墙,爬上然后旋转,直到其他边缘撞到隐形墙。我相信我需要设定一个不变的中心。我该怎么做?在我的代码中我应该把中心放在哪里?我看过很多例子,但似乎这种奇怪的轮换一直在发生。这是我的代码:

def update_angle(self):
    orig_car = self.car1
    loc = orig_car.get_rect().center
    car2 = pygame.transform.rotate(orig_car, self.angle)
    car2.get_rect().center = loc
    return car2

【问题讨论】:

标签: python pygame


【解决方案1】:

我遇到了与您类似的问题,我设法将少量代码放在一起来修复它。当您将汽车传送到屏幕上时,请使用以下代码:

rect = car2.get_rect(center=(200,200)) #Set the centre of rotation
SCREEN.blit(car2, rect)

它允许图像围绕一个点旋转,希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2013-09-22
    • 2021-09-01
    • 2015-04-13
    • 2011-05-10
    • 2016-07-31
    • 1970-01-01
    相关资源
    最近更新 更多