I have a sprite that i can move with my mouse and it is supposed to shoot a material every second ive used an example from another question for help where they used this.
time_counter=clock.tick()
if time_counter>1000:
material_group.add(Producer.create_material('self'))
time_counter=0
ive put it in the while loop that runs the game as if i put it into its own while loop then the game itself doesn't run. when i put it into the game loop it doesn't output anything but if i reduce the ticks to 10 it only runs the command when i'm moving the sprite but this doesn't happen for longer than 22
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
material_group.add(Producer.create_material('self'))
if game_active:
screen.blit(bg_surface,(0,0))
material_group.draw(screen)
producer_group.draw(screen)
producer_group.update()
material_group.update()
time_counter=clock.tick()
if time_counter>10:
material_group.add(Producer.create_material('self'))
print('hi')
time_counter=0
pygame.display.update()
clock.tick(120)
these are my sprite classes
class Producer(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image=pygame.image.load('producer.png').convert_alpha()
self.image=pygame.transform.rotate(self.image,90)
self.rect=self.image.get_rect(center=(200,200))
def update(self):
self.rect.center= pygame.mouse.get_pos()
def create_material(self):
return Material(pygame.mouse.get_pos()[0],pygame.mouse.get_pos()[1])
#return Material(self.x,self.y)
class Material(pygame.sprite.Sprite):
def __init__(self,x,y):
super().__init__()
self.image=pygame.Surface((30,30))
self.image.fill((255,0,0 ))
self.rect=self.image.get_rect(center=(x,y))
def update(self):
self.rect.x+=5
if self.rect.x>=800+200:
self.kill()
if any more info is needed please tell thanks.