【问题标题】:While loop stops at if statement - pygameWhile 循环在 if 语句处停止 - pygame
【发布时间】:2018-12-16 10:21:13
【问题描述】:

每当我运行此代码时,它都会在 screen.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()

【问题讨论】:

    标签: python pygame pygame-surface


    【解决方案1】:

    如果您查看 else 语句,您需要缩进 'print' 调用以与 'cImage += 1' 对齐。

    ----来自代码示例的sn-p----

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

    -------结束码sn-p---------------

    【讨论】:

      猜你喜欢
      • 2014-07-13
      • 2014-07-01
      • 2022-09-29
      • 2015-05-19
      • 2013-06-09
      • 2014-01-21
      • 2015-11-08
      • 2016-01-12
      • 2014-12-29
      相关资源
      最近更新 更多