本文整理匯總了Python中pygame.sprite.Group.clear方法的典型用法代碼示例。如果您正苦於以下問題:Python Group.clear方法的具體用法?Python Group.clear怎麽用?Python Group.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pygame.sprite.Group
的用法示例。
在下文中一共展示了Group.clear方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import clear [as 別名]
class Panel:
def __init__(self, world_map):
self.world_map = world_map
self.group = Group()
self.energy_bar = EnergyBar(world_map.main_character, 15, 10, self.group)
self.energy_bar.put(75, 13)
self.energy_bar = LifeBar(world_map.main_character, 15, 10, self.group)
self.energy_bar.put(75, 30)
self.rect = Rect(0, 0, SCREEN_W, 40)
self.background = data.load_image('panel.png')
font = Font(data.filepath('fonts', 'vera.ttf'), 12)
#font.set_bold(True)
self.twister_text = font.render("Twister:", True, (0,0,0))
self.life_text = font.render("Life:", True, (0,0,0))
self.world_text = font.render("World: %s" % world_map.name, True, (0,0,0))
class TimeText(Sprite):
def __init__(self, world_map, *groups):
Sprite.__init__(self, *groups)
self.world_map = world_map
def update(self, *args):
time = self.world_map.time
time_str = self.world_map.get_time()
if time < 60:
color = (170, 0, 0)
elif time < 120:
color = (255, 100, 0)
else:
color = (0, 0, 0)
self.image = font.render("Time: %s"% time_str , True, color)
self.rect = self.image.get_rect()
self.rect.move_ip(500, 0)
TimeText(world_map, self.group)
self.key = KeyItem(world_map)
self.key.put(620, 20)
self.key.remove(self.key.groups())
def draw(self, screen):
if self.world_map.got_key:
self.key.add(self.group)
screen.set_clip(self.rect)
self.group.clear(screen, self.background)
self.group.update()
self.group.draw(screen)
def draw_background(self, screen):
screen.blit(self.background, (0,0))
screen.blit(self.twister_text, (10, 0))
screen.blit(self.life_text, (10, 17))
screen.blit(self.world_text, (500, 17))
示例2: randint
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import clear [as 別名]
for e in event.get():
if e.type == QUIT:
done = True
elif e.type == KEYDOWN:
if e.key == K_ESCAPE:
done = True
elif e.unicode == u'r':
generation = randint(0,500)
index = randint(0,10000)
while not personat(generation, index):
index += 1
describeperson(generation, index)
elif e.type == MOUSEBUTTONDOWN and e.button == 1:
for sprite in sprites:
if sprite.rect.collidepoint(e.pos) and sprite.exists:
generation = sprite.rect.left / 8
index = sprite.rect.top / 8
describeperson(generation, index)
break
sprites.update()
sprites.clear(screen, background)
sprites.draw(screen)
display.flip()
limit.tick(20)