我在我的代码中有一个主循环,它循环所有的东西,当我运行我的代码时,我得到了这个错误:
Traceback (most recent call last):
File "C:\Users\Javier\Documents\Python Pygame\First Game\First
Game.py", line 17, in <module>
clock=pygame.time.clock()
AttributeError: module 'pygame.time' has no attribute 'clock'我知道错误是什么:这意味着它找不到‘clock’类,在我使用pygame.tick.clock()的另一个实例中,我得到了同样的错误。
#import modules here
import pygame
#define what colours are
black=(0,0,0)
white=(255,255,255)
turquoise=(64,224,208)
#initalise pygame
pygame.init()
#set up screen
screen=pygame.display.set_mode((400,400))
#what the screen is called and backgroud colour
screen.fill(black)
pygame.display.set_caption("Snake!")
#set a variable for how quick the game runs
clock=pygame.time.clock()
'''making future references easier
eval just takes code as a string and runs it
eg:
instead of doing print(5+8)
you can do eval(print(5+8))'''
def key(key):
return pygame.ket.get_pressed()[eval("pygame.K_"+key)]
#draw the snake
snake=(50,150,150,50)
#display.flip shows what has been drawn on the screen eg the snake
while True:
pygame.draw.rect(screen,turquoise,snake)
pygame.display.flip()
clock.tick(60)当我注释问题代码(clock.tick()和pygame.time.clock)时,窗口会打开并显示青绿色的“蛇”,但它没有降低循环执行速度的限制因素。
发布于 2017-06-07 04:18:42
要使用pygame时钟:
clock = pygame.time.Clock()然后,
clock.tick(60)发布于 2017-06-07 04:10:13
我相信是pygame.time.Clock和pygame.time.Clock.tick
https://www.pygame.org/docs/ref/time.html#pygame.time.Clock
正如您所注意到的,模块找不到类Clock。在Python中,类的约定是大写。
发布于 2017-06-07 04:12:20
想想看,但记录上说
pygame.time.Clock请注意时钟与小写字母中的大写字母C。
https://stackoverflow.com/questions/44398894
复制相似问题