Python & Pygame: Updating all elements in a list under a loop during iteration

前端 未结 3 849
花落未央
花落未央 2021-01-07 14:46

i am working on a program in Python and using Pygame. this is what the basic code looks like:

while 1:

   screen.blit(background, (0,0))
   for event in pyg         


        
3条回答
  •  一个人的身影
    2021-01-07 15:34

    edit: I thought you already tried : https://stackoverflow.com/a/11172885/341744

    The program, works, it draws the circles upon user input but the update problem is the only issue i need to solve. Is there any possible way to have all elements in the list of objects being updated by the while loop?

    You could iterate on a temporary list, for example, if you kill actors while iterating.

    for circle in circles[:]:
        circle.update()
    

提交回复
热议问题