2
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
 File "C:\Users\\OneDrive\Documents\Turtle\turtletest.py", line 52, in draw
  `win.blit(char, (self.x,self.y))`
TypeError: argument 1 must be pygame.Surface, not list

now this is my code

    class player(object):
    def __init__(self, x, y, width, height) :
        self.x = x
        self.y = y
        self.width = 42
        self.height = 45
        self.vel = 5
        self.left = False
        self.right = False
        self.up = False
        self.down = False
        self.walkCount = 0    

    def draw(self,win) :
        if self.walkCount + 1 >= 27:
            self.walkCount = 0
        if self.left:
            win.blit(walkLeft[self.walkCount//3], (self.x,self.y))
            self.walkCount += 1
        elif self.right:
            win.blit(walkRight[self.walkCount//3], (self.x,self.y))
            self.walkCount += 1
        if self.up:
            win.blit(walkUp[self.walkCount//3], (self.x,self.y))
            self.walkCount += 1
        elif self.down:
            win.blit(walkDown[walkcount//3], (self.x,self.y))
            self.walkCount += 1
        else:
            win.blit(char, (self.x,self.y))


def redrawGameWindow():
 # fills screen with a background color    
    win.fill(WHITE)
    turtle.draw(win)
    pygame.display.update()



#main loop for
turtle = player(300, 410, 42, 45)
run = True
while run:
    clock.tick(27)

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

    keys = pygame.key.get_pressed()
#left
    if keys[pygame.K_LEFT] and trutle.x > turtle.vel:
        turtle.x -= turtle.vel
        turtle.left = True
        turtle.right = False
#right
    elif keys[pygame.K_RIGHT] and turtle.x < windowX - turtle.width - turtle.vel:
        turtle.x += turtle.vel
        turtle.right = True
        turtle.left = False
    else:
        turtle.right = False
        turtle.left = False
        turtle.walkCount = 0

# up
    if keys[pygame.K_UP] and turtle.y > turtle.vel:
        turtle.y -= turtle.vel
        turtle.up = True
        turtle.down = False
#down
    if keys[pygame.K_DOWN] and turtle.y < windowY - turtle.width - turtle.vel:
        turtle.y += turtle.vel
        turtle.down = True
        turtle.up = False

    redrawGameWindow()


pygame.quit()```
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Sinfro
  • 23
  • 4

1 Answers1

1

I assume that char is a list of pygame.Surface objects with a single element.

char = [pygame.image.load(...)]

If the list "char" contains a single surface, then don't create a list. Instead just assign the loaded Surface object to the variable char (just remove the square brackets [, ]):

char = pygame.image.load(...)

Or use the 1st Surface object (char[0]) in the list in draw:

win.blit(char[0], (self.x,self.y))
Rabbid76
  • 202,892
  • 27
  • 131
  • 174