1
skier.move(hastighet)

self.rect.centerx = self.rect.centerx + speed[0]

I was not able to post my entire code here cause this website thought it wasn't properly formatted.

I get the error message

'ClassSkier' has no attribute 'rect'

I literally copied this code from a book so I have no idea why it's not working. The faulty lines are the ones i copied in above.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Erik B
  • 11
  • 1
  • Read the error message! It means that the class 'ClassSkier' has not attribute `.rect`. In other words `self.rect` does not exist. Probably you have to set `self.rect` in the constructor of the class `ClassSkier`. Possibly `self.rect = self.image.get_rect()`? – Rabbid76 Apr 14 '20 at 11:07
  • Python is trying to tell you that `skier` doesn't have an attribute `rect`. This probably means it hasn't been initialized. We can't help you more with the info you've provided. – Rohan Apr 14 '20 at 11:08
  • Usually, when working with pygame and its Sprite class, you set the `image` and `rect` attribute in the `__init__` method of your sprite subclass. You should at post the code of that class. – sloth Apr 14 '20 at 11:09
  • Fixed it, thank you – Erik B Apr 15 '20 at 13:14

0 Answers0