卡在零件的一般移动上,可能使用get_rect()

时间:2019-07-10 13:14:15

标签: python pygame chess

我在理解如何移动碎片时遇到了麻烦,我将所有碎片都加载为.png,并且不知道如何制作,因此我可以将其拖放到板上的不同位置。

我尝试使用get_rect(),但这不起作用。

,s02,s03,s04,s05,s06,s07,s08 = [80,80],[160,80],[240,80],[320,80],[400,80],[480,80],[560,80],[640,80]

w_pawn1,b_pawn1 = pygame.image.load("WhitePawn.png") ,pygame.image.load("BlackPawn.png") 


gameDisplay.blit(w_pawn1, (s09)),gameDisplay.blit(b_pawn1, (s49)),

def main():
    while True:
        event = pygame.event.wait()

        # if any mouse button is pressed
        if event.type == pygame.MOUSEBUTTONDOWN:
            print("Left clicked")
            event.pos = list(event.pos)
            x = event.pos[0]
            y = event.pos[1]
            xp = x / 80
            yp = y / 80

            x = round(xp)
            y = round(yp)
            x = x * 80
            y = y * 80
            del event.pos[0]
            del event.pos[0]
            event.pos.append(x)
            event.pos.append(y)
            print(event.pos)

            if w_pawn1.collidepoint(event.pos):
                w_pawn1_dragging = True
            #if event.pos in s_list:

        # if any mouse button is released
        if event.type == pygame.MOUSEBUTTONUP:

            print("Left released")
            event.pos = list(event.pos)
            x = event.pos[0]
            y = event.pos[1]
            xp = x / 80
            yp = y / 80

            x = round(xp)
            y = round(yp)
            x = x * 80
            y = y * 80
            del event.pos[0]
            del event.pos[0]
            event.pos.append(x)
            event.pos.append(y)
            print(event.pos)

            drag = 0
    pygame.quit()

if __name__ == '__main__':
    main()

输出:

AttributeError: 'str' object has no attribute 'get_rect'

0 个答案:

没有答案