我一直在努力使我的炮塔正确旋转,然而,当我移动鼠标(导致旋转)时,炮塔在油库上方旋转,是否有人知道一种简单的方法来解决这个问题?感谢帮助,请注意这是我第一次尝试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 uploud)
http://imageshack.us/a/img266/606/prntscrnpygame.png http://imageshack.us/a/img507/3848/prntscrnpygame2.png
请注意,我非常清楚旋转有点偏,我只是想先修复位置,希望我们能解决这个问题!
答案 0 :(得分:0)
感谢您发送电子邮件。你的问题是旋转中心是关闭的。你必须这样做才能使炮塔的中心成为图像的精确中心。我会通过电子邮件向你发送我的意思。