简体   繁体   English

python pygame blit函数

[英]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. 当我使用blit函数时,直到我调用“ display.fill(bgcolor)”函数时,它才会删除先前加载的精灵,以使精灵移动。 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 :( 注意-已经尝试过“ pygame.display.update()”和“ pygame.display.flip()”-它没有帮助:(

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. Blit永远不会删除前一个元素-不能-所有Blited元素都会创建一个位图。

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. 您还可以将pygame.display.update()与参数一起使用,以仅隐藏背景的某些部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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