标题:求助:AttributeError: 'Event' object has no attribute 'key'
只看楼主
shelly411430
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-6-3
 问题点数:0 回复次数:1 
求助:AttributeError: 'Event' object has no attribute 'key'
用python3.0和pycharm编程,代码如下:

import sys

import pygame

def check_event(ship):
    """响应按键和鼠标事件"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = True
            elif event.key == pygame.K_LEFT:
                ship.moving_left = True
        elif event.key == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = False
            elif event.key == pygame.K_LEFT:
                ship.moving_left = False


def update_screen(ai_settings, screen, ship):
    """更新屏幕上的图像,并切换到新屏幕"""
    screen.fill(ai_settings.bg_color)
    ship.blitme()

    # 让最近绘制的屏幕可见
    pygame.display.flip()
搜索更多相关主题的帖子: Event key 屏幕 pygame ship 
2020-06-03 15:22
shelly411430
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-6-3
得分:0 
发现错误,elif event.key == pygame.KEYUP: 应为 elif event.type == pygame.KEYUP:
2020-06-03 15:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-501946-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.244416 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved