Python Pygame error, «экземпляр спрайта не имеет метода __call__» - PullRequest
0 голосов
/ 15 мая 2018

Я пытаюсь сделать игру на Python с PyGame, я все еще довольно нуб, поэтому могут быть неправильные коды. Я пытаюсь изменить размер спрайта plane внутри класса sprite. Но я получаю сообщение об ошибке:

Сообщение об ошибке:

Traceback (most recent call last):
  File "/home/frei/Desktop/Projects/main.py", line 45, in <module>
    plane.resize(200,200)

File "/home/frei/Desktop/Projects/main.py", line 23, in resize
    pygame.transform.scale(self(sizex,sizey))

AttributeError: sprite instance has no __call__ method

И код:

#Import the library PyGame
import pygame; pygame.init()

window = pygame.display.set_mode((800, 800))
pygame.display.set_caption('Space Invaders')

class sprite:
    """A class that consists of a x value and a y value
        Y is up and X is down"""

    def __init__(self):
        self.x = 250
        self.y = 200

    def draw(self, string, window):
        global image
        image = pygame.image.load(string).convert()
        window.fill(0)
        window.blit(image, (self.x, self.y))
        pygame.display.flip()

    def resize(self,sizex,sizey):
        pygame.transform.scale(self(sizex,sizey))

# Load all images and assign them to variables
bakgrunn = pygame.image.load("stars.png").convert()

#Assign the variable plane to the class "sprite"
plane = sprite()

def draw_on_screen(image, x, y):
    window.fill(0)
    # Draw the image loaded
    window.blit(image, (x, y))
    pygame.display.flip()


#pygame.transform.scale(bakgrunn, (800, 500))

clock = pygame.time.Clock()

while True:
    clock.tick(30)
    plane.draw("plane.gif", window)
    plane.resize(200,200)

    keys = pygame.key.get_pressed()  # checking pressed keys
    if keys[pygame.K_LEFT]:
        plane.x -= 2
    if keys[pygame.K_RIGHT]:
        plane.x += 2
    if keys[pygame.K_UP]:
        plane.y -= 2
    if keys[pygame.K_DOWN]:
        plane.y += 2
    if keys[pygame.K_RETURN]:
        pygame.quit()
        exit()

    if keys[pygame.K_DOWN]:
        pass

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit();
            exit()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...