我一直在尝试使我的炮塔正确旋转,但是,当我移动鼠标(导致旋转)时,炮塔会在油箱底座上方旋转,有人知道解决此问题的简单方法吗?帮助将不胜感激,请注意这是我第一次尝试 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
请注意,我很清楚旋转有点偏离,我只是想先修复位置,希望我们能解决这个问题!