So I'm trying to make it so that every second a new material is created at the coordinates of all the producers which is being done by the change event and my producer list but the materials when moving the previous position still remains even though I've blit the grid png. Apologies for bad spag
class Producer(pygame.sprite.Sprite):
def __init__(self,x,y):
super().__init__()
self.image=pygame.image.load('images/producer.png').convert_alpha()
self.image=pygame.transform.rotate(self.image,90)
self.image=pygame.transform.scale(self.image, (40, 40))
self.rect=self.image.get_rect(topleft=(x,y))
def update(self):
producer_group.draw(screen)
def create_material(self,co):
return Material(co)
class Material(pygame.sprite.Sprite):
def __init__(self,co):
global producer_info
super().__init__()
self.image=pygame.Surface((10,10))
self.image.fill((255,0,0 ))
self.rect=self.image.get_rect(center=co)
def update(self):
x,y=co[0],co[1]
decimal_co=str(x)+'.'+str(y)
this_producer_info=producer_info.get(decimal_co)
self.rect.y-=5
print('material moving')
in the game loop
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
exit()
if event.type ==change_event:
if game_state=='play':
screen.blit(grid_surface,(0,100))
producer_cos=list(producer_info.keys())
for x in producer_cos:
co = x.split('.')
co[0]=int(co[0])
co[1]=int(co[1])
print(co)
material_group.add(Producer.create_material('self',co))
play game state
elif game_state=='play':
screen.blit(grid_surface,(0,100))
#buttons
settings_mini_button.draw()
shop_button.draw()
edit_button.draw()
blueprints_button.draw()
map_button.draw()
#machine stuff
producer_group.draw(grid_surface)
producer_group.update()
crafter_group.draw(grid_surface)
#producer_group.update(grid_surface)
#materials
material_group.draw(grid_surface)
material_group.update()
screen.blit(grid_surface,(0,100))
#copy screen
play_bg=screen.copy()