Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

python - Move sprite in pygame without flickering


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The typical Pygame application loop has to:

Remove screen.fill(BLACK) form update:

class Sprite(pygame.sprite.Sprite):
    # [...]
    
    def update(self, moveX, moveY):
        self.rect.x += moveX
        self.rect.y += moveY
        # screen.fill(BLACK)         <--- DELETE

Implement the following application loop (based on your previous question):

while carryOn == True:

    # handle events
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            carryOn=False

    # update
    # [...]

    # clear display
    screen.fill(BLACK)

    # draw sprites
    all_sprites_list.draw(screen)

    # update display
    pygame.display.flip()
    clock.tick(60)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...