python pygame blit 函数 [英] python pygame blit function

查看:149
本文介绍了python pygame blit 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 blit 函数时,它不会删除之前加载的精灵以使精灵移动,直到我调用display.fill(bgcolor)"函数.问题是我有一个多彩多姿的背景.那么如何在不影响背景的情况下更新图像?注意 - 已经尝试过pygame.display.update()"和pygame.display.flip()" - 它没有帮助:(

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))

我被困了很长时间:(

推荐答案

Blit 从不删除前一个元素 - 它不能 - 所有 blitted 元素创建一个位图.

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

您必须在所有循环中再次对所有元素进行 blit.

You have to blit all elements again in all loop.

或者你必须在 blit sprite 之前保留部分背景,稍后使用它来 blit 这部分代替 sprite 将其删除.

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.

您也可以使用带有参数的 pygame.display.update() 来仅对背景的某些部分进行 blit.

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

这篇关于python pygame blit 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆