我在弗雷迪的製作五晚的「迷遊戲」。我的代碼工作正常,直到我開始收到此錯誤:pygame的錯誤:clock.tick(40)AttributeError的:「功能」對象有沒有屬性「滴答」
File "C:\Users\Admin\Desktop\Python\Five Nights\Five Nights.py", line 116, in main
clock.tick(40)
AttributeError: 'function' object has no attribute 'tick'
我比較了代碼,其他工作pygame的遊戲,在時鐘的代碼是完全一樣的,但我只是在這場比賽中得到這個錯誤。
我的代碼如下:
import pygame, random
pygame.init()
screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN, 32)
pygame.display.toggle_fullscreen()
pygame.display.set_caption("Five Nights")
clock = pygame.time.Clock()
office_pic = pygame.image.load('images/office.png')
stage = pygame.image.load('images/stage.jpg')
building_map = pygame.image.load('images/map.png')
building_map.convert_alpha()
breathing = pygame.mixer.Sound('sounds/breathing.wav')
screen_width = 1280
screen_height = 800
x = 0
x_move = 0
v = 0
camera = stage
camera_up = False
click = None
fps_tick = 0
seconds = 0
hour = 10
def clock():
global fps_tick, seconds, hou
fps_tick += 1
if fps_tick == 40:
seconds += 1
fps_tick = 0
if seconds == 30:
hour += 1
def cameras(mouse_x, mouse_y):
global click, camera
screen.blit(camera, (0,0))
screen.blit(building_map, (screen_width-650, screen_height-426))
def main():
global x, x_move, camera_up, v, click
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
quit()
mouse_xy = pygame.mouse.get_pos()
mouse_x = mouse_xy[0]
mouse_y = mouse_xy[1]
click = pygame.mouse.get_pressed()
if mouse_x >= (screen_width/2) + 200 and mouse_x <= (screen_width/2) + 400:
x_move = 5
elif mouse_x <= (screen_width/2) - 200 and mouse_x >= (screen_width/2) - 400:
x_move = -5
elif mouse_x > (screen_width/2) + 400:
x_move = 10
elif mouse_x < (screen_width/2) - 400:
x_move = -10
else:
x_move = 0
x -= x_move
if mouse_y >= (screen_height - (screen_height/6)) and camera_up == False and v == 0:
camera_up = True
if not mouse_y >= (screen_height - (screen_height/6)) and camera_up == True:
v = 1
if mouse_y >= (screen_height - (screen_height/6)) and camera_up == True and v == 1:
screen.fill((0,0,0))
camera_up = False
if not mouse_y >= (screen_height - (screen_height/6)) and camera_up == False:
v = 0
if camera_up == False:
screen.blit(office_pic, (x,0))
if camera_up == True:
cameras(mouse_x, mouse_y)
pygame.display.update()
clock.tick(40)
main()