使用Pygame开发Python游戏时遇AttributeError:'tuple'对象无tick属性求助
解决Pygame中AttributeError: 'tuple' object has no attribute 'tick'的问题
错误根源在这一行代码:
clock = pygame,time.process_time()
这里的逗号会把pygame模块和time.process_time()的返回值打包成一个元组,而元组并没有tick方法。Pygame中实现帧率控制的正确方式是创建pygame.time.Clock()对象。
修正后的完整代码:
import pygame import time pygame.init() WIDTH, HEIGHT = 800, 500 pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Word Mystery!") FPS = 60 clock = pygame.time.Clock() # 正确的时钟对象创建方式 run = True while run: clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() print(pos) pygame.quit()
内容的提问来源于stack exchange,提问作者Shejal Pal
相关产品推荐
相关产品推荐

