Вы должны звонить pygame.event.get()
только один раз, так как он извлечет все события, которые произошли. Например:
a = pygame.event.get() # Contains the events that has happen.
for event in a:
if event.type == pygame.QUIT:
quit()
b = pygame.event.get() # Will probably contain nothing, as the code above took the events from the event queue.
for event in b:
if event.type == pygame.MOUSEBUTTONDOWN:
do_something()
do_some_calculation()
c = pygame.event.get() # Might contain something, if the user did something during the time it took to do the calculation.
for event in c:
if event.type == pygame.MOUSEBUTTONDOWN:
do_other_thing()
В приведенном выше примере, скорее всего, do_something()
никогда не будет вызвано, поскольку очередь событий была очищена только ранее. Можно вызвать do_other_thing()
, но это только , если пользователь нажал кнопку в течение времени, необходимого для выполнения do_some_calculations()
. Если пользователь нажал до или после, событие щелчка будет очищено и потеряно.
Итак, в вашей ситуации вы можете сделать что-то вроде этого:
class MainRun():
run = True
def Main(self):
#some code
while MainRun.run:
pygame.time.delay(35)
for event in pygame.event.get(): # ONLY CALLED HERE IN THE ENTIRE PROGRAM.
if event.type == pygame.QUIT:
MainRun.run = False
a.activate_skills(event) # MOVED THIS INTO THE FOR LOOP!
class Player():
#code
def activate_skills(self, event): # TAKING THE EVENT AS PARAMETER.
if event.type == pygame.MOUSEBUTTONDOWN:
#some code
a = Player
main = MainRun().Main()