简体   繁体   中英

python pygame blit function

When I use blit function, it does not delete the previous loaded sprite to make sprites move until I call the "display.fill(bgcolor)" function. The problem is that I have a multicolored background. so how do I update the image without affecting my background? NOTE - already tried "pygame.display.update()" and "pygame.display.flip()" - it doesn't help :(

class states():
def __init__(self, goku1,goku2, x, y):
    self.image=goku1
    keys=pygame.key.get_pressed()
    if keys[K_RIGHT]:
        self.image=goku2
    if keys[K_LEFT]:
        self.image=goku2

while True:
pygame.display.flip()
pygame.display.update()
obj=states(goku1, goku2, x, y)

call=position()
DISPLAYSURF.blit(obj.image, (x, y))

am stuck for long :(

You would blit the background first, and then blit the new location for the sprite that is moving. It would look something like this:

window= pygame.display.set_mode(WINDOWSIZE, 0, 32)

while True:
    #update events

    window.blit(your_multi_colored_background, (0, 0))
    window.blit(obj.image, (x, y))
    pygame.display.update()

Hope this helps.

Blit never delete previous element - it can't - all blitted elements create one bitmap.

You have to blit all elements again in all loop.

Or you have to keep part of background before you blit sprite and use it later to blit this part in place of sprite to remove it.

You can also use pygame.display.update() with arguments to blit only some parts of background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM