Python Forum
[PyGame] Beginning PyGame question about "self"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Beginning PyGame question about "self"
#1
Hello I am not sure how to really question my question if that makes sense. I am following metulburr's pygame tutorial and something I don't really understand is why when I make a class I have self. I have my example below but if someone could explain what self.*** actually does or clarify it simply that would help, also I see under the player class "def __init__" a lot why is __init__ commonly used?

class player:
    def __init__(self, screen_rect):
        self.image = pg.image.load('spaceship.png').contert()
        self.image.set_colorkey((255,0,255))
        self.rect = self.image.get_rect(center = screen_rect.center)

    def draw(self, surf):
        surf.blit(self.image, self.rect)
Reply


Messages In This Thread
Beginning PyGame question about "self" - by jakegold98 - Dec-08-2017, 07:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  question about my pygame code for space shooter Than999 4 2,536 Feb-07-2022, 03:55 AM
Last Post: metulburr
  question about my Pygame code Than999 2 1,694 Feb-06-2022, 10:03 PM
Last Post: Than999

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020