猿问

Pygame 枪在左侧问题上向上旋转视线向下

所以我这里有这把枪,它朝我的鼠标 x 和鼠标 y 位置旋转,但问题(视频)是枪倒置了。有没有办法让我的枪的图像不倒置,并做与我的枪朝向右侧相同的运动?就像左侧的枪由于某种原因倒置了,我根本不知道该怎么做

枪支图片:

my gun draw(self)


    def draw(self,drawX,drawY):


        self.rect.topleft =  (drawX,drawY)


            # the gun's hitbox


            # rotating the gun

        dx = self.look_at_pos[0] - self.rect.centerx

        dy = self.look_at_pos[1] - self.rect.centery 

            

        angle = (180/math.pi) * math.atan2(-dy, dx)

      

        gun_size = self.image.get_size()

        pivot = (8, gun_size[1]//2)

            


        blitRotate(window, self.image, self.rect.center, pivot, angle)


    def lookAt( self, coordinate ):

            

        self.look_at_pos = coordinate

我的全枪课


class handgun():

    def __init__(self,x,y,height,width,color):

        self.x = x

        self.y = y

        self.height = height

        self.width = width

        self.color = color

        self.rect = pygame.Rect(x,y,height,width)



        # LOL THESE IS THE HAND

        self.shootsright = pygame.image.load("hands.png")

        self.image = self.shootsright

        self.rect  = self.image.get_rect(center = (self.x, self.y))

        self.look_at_pos = (self.x, self.y)


        self.isLookingAtPlayer = False

        self.look_at_pos = (x,y)

            




        self.hitbox = (self.x + -18, self.y, 46,60)




    def draw(self,drawX,drawY):


        self.rect.topleft =  (drawX,drawY)


            # the gun's hitbox


            # rotating the gun

        dx = self.look_at_pos[0] - self.rect.centerx

        dy = self.look_at_pos[1] - self.rect.centery 

            

        angle = (180/math.pi) * math.atan2(-dy, dx)

      

        gun_size = self.image.get_size()

        pivot = (8, gun_size[1]//2)

            


        blitRotate(window, self.image, self.rect.center, pivot, angle)


    def lookAt( self, coordinate ):

            

        self.look_at_pos = coordinate




我的完整代码:感谢脚本 安迪的帮助谢谢!



偶然的你
浏览 85回答 0
0回答
随时随地看视频慕课网APP

相关分类

Python
我要回答