I'm currently reading Python Crash Course, and there is that code:
import pygame
class Ship():
def __init__(self, screen):
"""Initialize the ship, and set its starting position."""
self.screen = screen
# Load the ship image, and get its rect.
self.image = pygame.image.load('images/ship.bmp')
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
# Start each new ship at the bottom center of the screen.
self.rect.centerx = self.screen_rect.centerx
self.rect.bottom = self.screen_rect.bottom
I'm pretty sure i'm asking basic stuff, but nor my brain, nor my google skills aren't that good.
This thing: self.rect = self.image.get_rect(). Aren't get_rect() part of pygame.Screen module? If so, shouldn't it be used like pygame.Screen.get_rect()?
self.rect.centerx = self.screen_rect.centerx Too.many.dots. Is rect class instance, that is being created by get_rect() method, and centerx is attribute of that instance? Also, screen variable (or class instance?) is defined like that: screen = pygame.display.set_mode((1200, 800))
Thanks in advance!
Edit: Thanks for answers!
1.23) means accessing an attribute. The object which has the attribute (hopefully, or you get anAttributeError) is on the left (and can itself be an attribute of another object, as you see in your examples) and the name of the attribute is on the right. +1 for reading a tutorial, see sopython.com/wiki/What_tutorial_should_I_read%3F