Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pygame.Surface';对象不可调用_Python - Fatal编程技术网

Python pygame.Surface';对象不可调用

Python pygame.Surface';对象不可调用,python,Python,我已经搜索了一些问题,但它并没有真正回答我的问题 我是Python&Pygame新手,现在已经几周了:),正在做一个关于游戏开发的教程。 我这里有一个代码&它应该在屏幕上显示我的bug图像,但它没有,相反,我得到一个黑色窗口。。。 我哪里出错了 import pygame, sys pygame.init() WIDTH, HEIGHT = (800, 600) screen=pygame.display.set_mode((WIDTH, HEIGHT),0, 32) img_bug = p

我已经搜索了一些问题,但它并没有真正回答我的问题

我是Python&Pygame新手,现在已经几周了:),正在做一个关于游戏开发的教程。 我这里有一个代码&它应该在屏幕上显示我的bug图像,但它没有,相反,我得到一个黑色窗口。。。 我哪里出错了

import pygame, sys


pygame.init()
WIDTH, HEIGHT = (800, 600)
screen=pygame.display.set_mode((WIDTH, HEIGHT),0, 32)
img_bug = pygame.image.load("bug.png").convert_alpha()

clock = pygame.time.Clock()    
FPS = 24
fivesecondinterval = FPS * 5
totalframes = 0

while True: #Never ending loop
for event in pygame.event.get():   
    if event.type==pygame.QUIT:           
        pygame.quit()
        sys.exit()

totalframes += 1

if totalframes % fivesecondinterval ==0 :

screen.blit(img_bug, (200, 200))
pygame.display.flip()   
clock.tick(FPS)

您必须正确缩进代码。这应该起作用:

import pygame, sys

pygame.init()
WIDTH, HEIGHT = (800, 600)
screen=pygame.display.set_mode((WIDTH, HEIGHT),0, 32)
img_bug = pygame.image.load("bug.png").convert_alpha()

clock = pygame.time.Clock()    
FPS = 24
fivesecondinterval = FPS * 5
totalframes = 0

while True: #Never ending loop
    for event in pygame.event.get():   
        if event.type==pygame.QUIT:           
            pygame.quit()
            sys.exit()

    totalframes += 1

    if totalframes % fivesecondinterval ==0 :
        screen.blit(img_bug, (200, 200))
        pygame.display.flip()   
            clock.tick(FPS)
重要的一点是(在修复了导致异常的每个缩进错误之后)以下内容:


部分代码在循环中。

如果这解决了您的问题,请投票并将其标记为已接受。
if totalframes % fivesecondinterval==0:
    screen.blit(img_bug, (200, 200))
    pygame.display.flip()   
        clock.tick(FPS)