【发布时间】:2018-02-11 09:52:01
【问题描述】:
我正在使用 pygame 制作一个飞扬的小鸟克隆游戏。我想用 Sprite.draw 画柱子。我创建了一个Pillar 类,并在屏幕左侧用两个矩形p_upper 和p_lower 对其进行了初始化,借助精灵的update 函数朝向右侧。但屏幕只显示 p_lower 柱子。有人可以帮忙吗?
class Pillar(pygame.sprite.Sprite):
# the "h" parameter is height of upper pillar upto gap
# "w" is the width of the pillar
# pillar is coming from left to right
def __init__(self, w, h, gap):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((w, h))
self.image.fill(green)
self.p_upper = self.rect = self.image.get_rect()
self.p_upper.topleft = (-w, 0)
self.image = pygame.Surface((w, HEIGHT - (h + gap)))
self.image.fill(green)
self.p_lower = self.rect = self.image.get_rect()
self.p_lower.topleft = (-w, h + gap)
def update(self):
self.p_upper.x += 1
self.p_lower.x += 1
【问题讨论】: