1

**This is the senction my code tried the event.get for both keydown and mouse press it's just not function and also I put them in a function there I can control them but I do not know is that because of this

def bullet_launch():
    event_list = pygame.event.get()
    for event in event_list:
        if event.type == pygame.MOUSEBUTTONDOWN:

            print("a")
            cache = {
                'image': pygame.transform.scale(pygame.image.load('assets/bullet.png'), (bullet_scale)),
                'ypos': player["ypos"],
                'xpos': player["xpos"],
                'rad': math.radians(int(math.degrees(player["rad"])))
            }
            bullets.append(cache)
Ha0ran
  • 11
  • 2
  • its not even print – Ha0ran Apr 23 '20 at 00:50
  • 1
    That should work, Could you show all of your code – The Big Kahuna Apr 23 '20 at 00:58
  • where do you run `player_mov()` ? Maybe you never run it. – furas Apr 23 '20 at 01:23
  • 4
    BTW: do you have other event loop with `pygame.event.get():` ? If you have it then other loop get all events and this loop don't get any event. You have to use only one loop with `pygame.event.get():` And inside other loop you have to run `player_mov(event)` - with `event` - and function `player_mov()` has to check this even (without using `for event in pygame.event.get():`) – furas Apr 23 '20 at 01:24
  • the original code it's too long so I deteted some – Ha0ran Apr 23 '20 at 04:24
  • Still, if you want an answer to the question you will have to include more code. Also describe your previous attempts to fix the issue – Sebastiaan Apr 23 '20 at 06:17

1 Answers1

1

pygame.event.get() removes the events from the queue. If you have multiple event loops, then just one of the loops will get the events.
Retrieve the list of events just once per frame and pass the list to the functions and methods which evaluate the events:

e.g.:

def bullet_launch(event_list):
    for event in event_list:
        if event.type == pygame.MOUSEBUTTONDOWN:
            # [...]
while run:

    event_list = pygame.event.get()
    for event in event_list:
        if event.type == pygame.QUIT:
            run = False

    # [...]

    bullet_launch(event_list)

    # [...]
Rabbid76
  • 202,892
  • 27
  • 131
  • 174