Pygame Erasing Images on Backgrounds

后端 未结 3 884
北荒
北荒 2021-01-14 08:52

You blit an image onto your surface to use as your background. Then you press button X to blit an image on the same surface, how do you erase the image? I have this so far,

3条回答
  •  囚心锁ツ
    2021-01-14 09:12

    Normally the blit workflow is just to blit the original background to screen.

    In your code you would use screen.blit(background, (0,0))

    When you start combining lots of surfaces you will probably want either a variable or a list of variables to keep track of screen state.

    E.g.

    Initialise Background

    objectsonscreen = []
    objectsonscreen.append(background)
    screen.blit(background, (0,0))
    

    Add Sprite

    objectsonscreen.append(player)
    screen.blit(player, (x, y))
    

    Clear Sprite

    objectsonscreen = [background]
    screen.blit(background, (0,0))
    

    See here for more information on sprites in Pygame. Note that if your background isn't an image background and is just a solid color you could also use screen.fill([0, 0, 0]) instead.

提交回复
热议问题