python - Deleting/Removing the first N or last N from a sprites.Group() -
so let's have sprites group , added bunch of things it:
all_shelfs = pygame.sprite.group() shelf_tracking_list = [] #making shelfs build_lvl = height - 150 #group in xrange(100): wid = random.randint(120,320) pos = [random.randint(0, width-wid), random.randint(build_lvl-20, build_lvl), wid] all_shelfs.add(shelf(pos[0],pos[1], pos[2])) build_lvl = build_lvl - 60 #group b in xrange(100): wid = random.randint(120,320) pos = [random.randint(0, width-wid), random.randint(build_lvl-20, build_lvl), wid] all_shelfs.add(shelf(pos[0],pos[1], pos[2])) build_lvl = build_lvl - 60 #group c in xrange(100): wid = random.randint(120,320) pos = [random.randint(0, width-wid), random.randint(build_lvl-20, build_lvl), wid] all_shelfs.add(shelf(pos[0],pos[1], pos[2])) build_lvl = build_lvl - 60 shelf_tracking_list = all_shelfs.sprites()
how delete group example? first group added. noticed can't modify group using shelf_tracking_list
if keeping track of sprites in each group, use sprite.group.remove(*sprites)
function remove entire group, specified in docs here: http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.group.remove
# group group_a = list() in xrange(100): wid = random.randint(120,320) pos = [random.randint(0, width-wid), random.randint(build_lvl-20, build_lvl), wid] new_shelf = shelf(pos[0], pos[1], pos[2]) group_a.append(new_shelf) build_lvl = build_lvl - 60 all_shelfs.add(group_a)
then when want remove entire group all_shelfs
:
all_shelfs.remove(group_a)
Comments
Post a Comment