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 :(
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.You would blit the background first, and then blit the new location for the sprite that is moving. It would look something like this:
Hope this helps.