Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.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 While循环在if语句处停止-pygame_Python_Pygame_Pygame Surface - Fatal编程技术网

Python While循环在if语句处停止-pygame

Python While循环在if语句处停止-pygame,python,pygame,pygame-surface,Python,Pygame,Pygame Surface,每当我运行此代码时,它都会在屏幕前停止。blit同时仍在循环,反复打印'debug3' 它甚至不知道屏幕没有定义,我的目的是让它运行screen.blit ... playermove = 5 walkL=pygame.image.load("files/sprites/walkL.png") walkR=pygame.image.load("files/sprites/walkR.png") currentSprite = walkL #single sprite size (width,

每当我运行此代码时,它都会在
屏幕前停止。blit
同时仍在循环,反复打印
'debug3'

它甚至不知道屏幕没有定义,我的目的是让它运行
screen.blit

...
playermove = 5
walkL=pygame.image.load("files/sprites/walkL.png")
walkR=pygame.image.load("files/sprites/walkR.png")
currentSprite = walkL

#single sprite size (width, height)
h=128
w=57   
numImages = 4
    #counter
cImage=0


class Player:

    def animation(self):    
        global cImage,numImages,currentSprite,playerRect,w,h        
        if (cImage>=numImages-1):
            cImage=0
        else:
            cImage+=1
        print('debug3')

        screen.blit(currentSprite,playerRect, (cImage*w,0,w,h))

while True:
    player.animation()

如果查看else语句,则需要缩进“print”调用以与“cImage+=1”对齐

----来自代码示例的片段----


-------结束代码片段-----------------

如果查看else语句,则需要缩进“print”调用以与“cImage+=1”对齐

----来自代码示例的片段----

-------结束代码段---------------

    if (cImage>=numImages-1):
        cImage=0
    else:
        cImage+=1
    print('debug3')