1

I'm creating a game in which if a certain condition is met it will add the rect inside the array

tail.append(pygame.draw.rect(screen, (0, 0, 0), (350, 350, 25, 25)))

and while it did really add it in the array when I printed the array in the console, but the rect disappears immediately from the display game. I figured out that its because it only shows in when the the condition is met but after the coordinates changes it'll disappear which is only a second.

1 Answer 1

1

The entire scene has to be redrawn in each frame. You need to draw the rectangles in the main application loop. Create a pygame.Rect object and append it to tail when the condition is met:

tail.append(pygame.Rect(350, 350, 25, 25))

However, draw all the rectangles in tail in the application loop:

while True:

    # [...]

    for rect in tail:
        pygame.draw.rect(screen, (0, 0, 0), rect)

    # [...]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.