-1

I tried to make snake game but this part

def snakebody():
    no=0
    while no < length:
        snakebodyx=snakex[:no]
        snakebodyy=snakey[:no]
        pygame.draw.rect(win, Green, (snakebodyx,snakebodyy, size, size))

snakex and y is a list consisting of the memory of the snake head, so it can form its body. it tried extracting the variables of it and use it to get a coordinates of the bodies

However, it does not work it says TypeError: rect argument is invalid

Can anyone explain why?

I tried using win.fill, it failed making the rect become Rect, it still fail

Jack Ng
  • 9
  • 1
  • The third argument of [`draw.rect`](https://www.pygame.org/docs/ref/draw.html#pygame.draw.rect) is supposed to be a `Rect`. You pass it a tuple, and not only that, `snakebodyx` and `-y` are both lists. But they should be ints. Also, please always post a [mre] – Tomerikoo Dec 25 '22 at 08:34

1 Answers1

0

Try

pygame.draw.rect(screen, (r,g,b), pygame.Rect(X, Y, width, length), TheThicknessOfTheRectangle)

check out pygames official documentation for more information at: https://www.pygame.org/docs/ref/draw.html#pygame.draw.rect