且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

属性错误:成员未定义python

更新时间:2022-06-15 23:13:38

使用event.key之前必须检查event.type == pygame.KEYDOWNevent.type == pygame.KEYUP,因为并非所有事件都定义了event.key.

You have to check event.type == pygame.KEYDOWN or event.type == pygame.KEYUP before you use event.key because not all events have event.key defined.

while True: 
    for event in pygame.event.get():
        if event.type == pygame.QUIT: 
            sys.exit()
        elif event.type == pygame.KEYDOWN: 
            if event.key == pygame.K_w:    #line 82
                player.walkNorthAnimation()

请参阅PyGame文档:事件

see PyGame documentation: Event

QUIT             none
ACTIVEEVENT      gain, state
KEYDOWN          unicode, key, mod
KEYUP            key, mod
MOUSEMOTION      pos, rel, buttons
MOUSEBUTTONUP    pos, button
MOUSEBUTTONDOWN  pos, button
JOYAXISMOTION    joy, axis, value
JOYBALLMOTION    joy, ball, rel
JOYHATMOTION     joy, hat, value
JOYBUTTONUP      joy, button
JOYBUTTONDOWN    joy, button
VIDEORESIZE      size, w, h
VIDEOEXPOSE      none
USEREVENT        code