【问题标题】:Pygame - Pygame keeps drawing more sprites after moving themPygame - Pygame 在移动精灵后不断绘制更多精灵
【发布时间】:2016-08-19 07:34:31
【问题描述】:

no idea what's wrong

不让我发布完整代码,搜索了这个网站和谷歌,但没有找到答案......

DISPLAYSURF=pygame.display.set_mode((width,height),0,32)

sprite=pygame.image.load('generic_legionnary.png'

def move(direction, sprite, spritex, spritey):
    if direction:
        if direction == K_UP:
            spritey-=5
            sprite=pygame.image.load('generic_legionnary.png')
        elif direction == K_DOWN:
            spritey+=5
            sprite=pygame.image.load('generic_legionnary.png')
        if direction == K_LEFT:
            spritex-=5
            sprite=pygame.image.load('generic_legionnary.png')
        elif direction == K_RIGHT:
            spritex+=5
            sprite=pygame.image.load('generic_legionnary.png')
    return sprite, spritex, spritey

while True:

    DISPLAYSURF.blit(sprite,(spritex,spritey))

不知道怎么回事,移动的时候不断放新图,怎么确定只有一张图在移动? 谢谢!

编辑:解决了

screen.fill((255,255,255))

设置背景色,描边的东西消失

【问题讨论】:

    标签: python pygame


    【解决方案1】:

    您是否在每个循环开始时清除屏幕?

    为什么每次移动时都加载新的精灵?

    谁只需要在函数之前加载的那个,而不需要其他的。

    如果您没有在每个循环中清除屏幕,则会得到此跟踪。 (或者你的痕迹可能是你已经覆盖的旧精灵,但通常垃圾收集器应该摆脱它们。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多