0

我一直在尝试使我的炮塔正确旋转,但是,当我移动鼠标(导致旋转)时,炮塔会在油箱底座上方旋转,有人知道解决此问题的简单方法吗?帮助将不胜感激,请注意这是我第一次尝试 pygame

代码:

#Rotation
mousex,mousey = pygame.mouse.get_pos()
CalcHeight = cannonBase.y - mousey
CalcWidth = cannonBase.x - mousex
if CalcWidth == 0:
   CalcWidth = 1
CalcRot = CalcHeight/float(CalcWidth)
rot = math.degrees(math.atan(CalcRot))

OldCenter = cannonBase.center
rot_image,rot_rect = rot_center(cannon_original, cannonBase, rot)
cannonBaseStretchedImage = rot_image


#Rot_center
def rot_center(image, rect, angle):
     """rotate an image while keeping its center"""
     rot_image = pygame.transform.rotate(image, angle)
     rot_rect = rot_image.get_rect(center=rect.center)
     return rot_image,rot_rect

(我第一次发帖,请告诉我我的帖子是否难以阅读或理解)

*添加图片

感谢您的快速回复,这里有 2 张图片(由于我的成绩太低,无法通过 stackoverflow 上传)

http://imageshack.us/a/img266/606/prntscrnpygame.png http://imageshack.us/a/img507/3848/prntscrnpygame2.png

请注意,我很清楚旋转有点偏离,我只是想先修复位置,希望我们能解决这个问题!

4

1 回答 1

0

感谢您的电子邮件。您的问题是旋转中心已关闭。你必须做到这一点,使炮塔的中心是图像的确切中心。我会通过电子邮件将我的意思的图片发给你。

于 2013-01-04T19:40:34.673 回答