Answer the question
In order to leave comments, you need to log in
Why can't I create a character using a class?
from pygame import *
window = display.set_mode((600, 600))
display.set_caption("Шлёпа")
class Flopa(sprite.Sprite):
def __init__(self, image, x, y,):
sprite.Sprite.__init__(self)
self.image = transform.scale(image.load("flopa.png"), (50, 50))
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
def update(self):
keys = key.get_pressed()
if keys[K_LEFT]:
self.rect.x -= 5
if keys[K_RIGHT]:
self.rect.x += 5
run = True
while run:
for e in event.get():
if e.type == KEYDOWN:
if e.key == K_ESCAPE:
run = False
flopa = Flopa("flopa.png", 100, 100)
flopa.update()
window.fill((250,250,250))
time.delay(20)
display.update()
self.image = transform.scale(image.load("flopa.png"), (50, 50))
AttributeError: 'str' object has no attribute 'load'
Answer the question
In order to leave comments, you need to log in
You are using image as an argument to Flopa.__init__,
just change
to
and instead of
def __init__(self, image, x, y,):
def __init__(self, _image, x, y,):
self.image = transform.scale(image.load("flopa.png"), (50, 50))
self.image = transform.scale(image.load(_image), (50, 50))
def __init__(self, image, x, y>>,<<)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question