I have been working with pygame recently. I started putting my sprites in a class now but I have encountered a problem. I put my character tank
in the init module. Then added my class Player
to a GroupSingle (called player
). But when trying to draw the group i encounter this problem:
TypeError: AbstractGroup.draw() missing 1 required positional argument: 'surface'
This is my code:
import pygame
pygame.init()
class Player:
def __init__(self):
super().__init__()
#create sprite
self.tank = pygame.image.load("Graphics/Tank.jpg").convert_alpha()
self.rect = self.tank.get_rect(midbottom = (200, 300))
screen = pygame.display.set_mode((800, 400))
clock = pygame.time.Clock()
#make group
player = pygame.sprite.GroupSingle
player.add(Player())
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
screen.fill("black")
#draw group
player.draw(screen)
pygame.display.update()
clock.tick(60)
I have no idea what I might be doing wrong. This might turn turn out to be a very stupid mistake but I am still a beginner.